Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7537699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:55:19+00:00 2026-05-30T06:55:19+00:00

I know it is possible to play iPod Songs using AVPlayer, but I cannot

  • 0

I know it is possible to play iPod Songs using AVPlayer, but I cannot figure out how to initialize the AVAudioPlayer with an iPod song URL using initWithContentsOfURL. When I try, the AVAudioPlayer returns NULL upon initialization.

I need to use AVAudioPlayer because I need to use its delegate method audioPlayerDidFinishPlaying for further processing when my app runs in the background (i.e. the AVAudioPlayer delegate method audioPlayerDidFinishPlaying gets called if the app is running in the background. But the AVPlayer does not provide delegate methods, so you can only use notifications which don’t run in the background).

The following code is for playing an iPod song with the AVPlayer.

- (void)viewDidLoad {

    [super viewDidLoad];
    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayback error:nil];
    NSError *error = nil;

    [session setActive:YES error:&error];
    MPMediaQuery *query = [MPMediaQuery songsQuery];
    NSArray *collection = [query items];
    MPMediaItem *item = [collection objectAtIndex:0];
    NSLog(@"%@",[item valueForProperty:MPMediaItemPropertyTitle]);
    NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
    AVPlayer *player = [[AVPlayer alloc]initWithURL:url];   // <-- Line to Replace
    [player play];
}

This works great. But if I replace the second to last line with the following:

    AVAudioPlayer *player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];

the call to initWithContentsOfURL returns NULL.

Any thoughts about why this returns NULL when I use AVAudioPlayer, but returns an initialized player when I use AVPlayer?

According the the Technical Q&A http://developer.apple.com/library/ios/#qa/qa1634/_index.html, “the URL used with initWithContentsOfURL: must be a File URL (file://). That is, a local path.”

When I obtain the url for the song in my iPod Library, the path is:

ipod-library://item/item.mp3?id=-4017276016911605928

Would you say that this path to my iPod library is not considered a “local path” or would you consider it a bug that initWithContentsOfURL is returning NULL?

Thoughts anyone?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:55:20+00:00Added an answer on May 30, 2026 at 6:55 am

    You have sort of answered your own question because from what I can gather it is the url path that is important for AVAudioPlayer, and it has to be local to the bundle. There is an example of using AVPlayer with notifications, search AVPlayerDemo for playerItemDidReachEnd but I cannot tell you whether it runs in background or foreground.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know its possible to open an app from mobile safari using custom URL
I am using AVPlayer to play an audio stream, and it's possible to keep
I would like to know if is possible to play a SYSTEM sound using
I know its possible to receive a dayClick event on Fullcalendar. But I would
Can anybody help me out to know the possible reasons for which Apple store
I know it's possible, and I've seen simple examples in the documentation, but are
Is it possible to play an embedded AAC file in Flash/Flex somehow? I know
I'm using Matt Gallagher's AudioStreamer to play MP3s over HTTP. I need to know
i want to know if it is possible to play a video via flash
I would like to know if it's possible to play a video from an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.