• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AVAudioPlayer with MPMediaItemPropertyAssetURL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AVAudioPlayer with MPMediaItemPropertyAssetURL


  • Subject: Re: AVAudioPlayer with MPMediaItemPropertyAssetURL
  • From: Mark <email@hidden>
  • Date: Sat, 15 Sep 2012 19:30:54 +1000

Hi,

An AVAudioPlayer can't play an item from the Media Library directly... the assetURL returned is not a file-system relative URL, it is more of a private reference to the media item and can only be played directly by an MPMediaPlayer. For use in an AVPlayer / AVAudioPlayer what you have to do is create an AVAssetExport session using that assetURL, which is then used to copy the file from the Media Library into your apps container i.e. your Documents  or Temporary folder. Once that process is done you then load the asset from the copied files app-local URL. Take a look at 'TSLibraryImport' to see one example of how the file export / import can be done:

http://code.google.com/p/tslibraryimport/

HTH,

Mark Hill
MachineCodex Software
http://www.machinecodex.com


On 15/09/2012, at 6:40 PM, Richard Oths wrote:

Greetings.

Trying to use MPMediaPickerController  to pass user-chosen song URL into AVAudioPlayer init. Code compiles but nothing plays. Is this even possible? Here's what I've got...

- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection 
{


    [self dismissModalViewControllerAnimated:YES];
if ([mediaItemCollection count] < 1) {
return;
}
//[song release];
song = [[mediaItemCollection items] objectAtIndex:0];
    songLabel.hidden = NO;
artistLabel.hidden = NO;
    imgButton.hidden = NO;
artwork = [song valueForProperty: MPMediaItemPropertyArtwork];
    //coverArtView.hidden = NO;
songLabel.text = [song valueForProperty:MPMediaItemPropertyTitle];
    artistLabel.text = [song valueForProperty:MPMediaItemPropertyArtist];
    audioURL = [song valueForProperty:MPMediaItemPropertyAssetURL]; 
    audioDuration = [song valueForProperty:MPMediaItemPropertyPlaybackDuration];    
audioBPM = [song valueForProperty:MPMediaItemPropertyBeatsPerMinute];    

    

    //Play audio
    NSString *resourcePath = [NSString stringWithFormat:@"%@",[audioURL absoluteString]];
    NSData *soundData = [NSData dataWithContentsOfURL:audioURL];
    audioPlayer = [[AVAudioPlayer alloc] initWithData:soundData error: nil];
    audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath isDirectory:FALSE] error:nil]; 
    //audioPlayer.delegate = self; <<I'll have to resolve this for as of now, MPMediaController is delegate, not AVAudioPlayer
    [audioPlayer prepareToPlay];
    [audioPlayer setVolume: 1.0];
    [audioPlayer setDelegate: self];
    [audioPlayer play];

Many thanks



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: AVAudioPlayer with MPMediaItemPropertyAssetURL
      • From: Bill Phillips <email@hidden>
References: 
 >AVAudioPlayer with MPMediaItemPropertyAssetURL (From: Richard Oths <email@hidden>)

  • Prev by Date: Correction: AVAudioPlayer with MPMediaItemPropertyAssetURL
  • Next by Date: Re: AVAudioPlayer with MPMediaItemPropertyAssetURL
  • Previous by thread: AVAudioPlayer with MPMediaItemPropertyAssetURL
  • Next by thread: Re: AVAudioPlayer with MPMediaItemPropertyAssetURL
  • Index(es):
    • Date
    • Thread