• 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: Richard Oths <email@hidden>
  • Date: Sat, 15 Sep 2012 09:51:41 -0500

Thank you so much for all the input. To be truthful, I'm using an AudioQueue to generate sine waves atop a musical selection and the 'logistics' of choosing the audio was dogging me. I appreciate the input and will keep the inquiries strictly Core Audio thus forth.

Richard


On Sat, Sep 15, 2012 at 8:15 AM, Bill Phillips <email@hidden> wrote:
Two things:

1) This mailing list is for CoreAudio discussion, not AVFoundation (as
far as I'm aware, at least). Check out the forums on the iOS Dev
Portal for AVFoundation discussion.

2) Mark is half right here. It is true that Media Library URLs are not
simple file system paths, and that you cannot play them in
AVAudioPlayer. However, you *can* play them using AVPlayer. Use the
URL to create an AVURLAsset, which you can then play directly using an
AVPlayer without exporting anything.

On Sat, Sep 15, 2012 at 5:30 AM, Mark <email@hidden> wrote:
> 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
>

 _______________________________________________
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

References: 
 >AVAudioPlayer with MPMediaItemPropertyAssetURL (From: Richard Oths <email@hidden>)
 >Re: AVAudioPlayer with MPMediaItemPropertyAssetURL (From: Mark <email@hidden>)
 >Re: AVAudioPlayer with MPMediaItemPropertyAssetURL (From: Bill Phillips <email@hidden>)

  • Prev by Date: Re: AVAudioPlayer with MPMediaItemPropertyAssetURL
  • Next by Date: kAudioUnitProperty_ContextName - get track information
  • Previous by thread: Re: AVAudioPlayer with MPMediaItemPropertyAssetURL
  • Next by thread: Correction: AVAudioPlayer with MPMediaItemPropertyAssetURL
  • Index(es):
    • Date
    • Thread