• 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
AVAudioPlayer with MPMediaItemPropertyAssetURL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AVAudioPlayer with MPMediaItemPropertyAssetURL


  • Subject: AVAudioPlayer with MPMediaItemPropertyAssetURL
  • From: Richard Oths <email@hidden>
  • Date: Sat, 15 Sep 2012 03:40:57 -0500

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: Mark <email@hidden>
  • Prev by Date: Re: possible to detect if headphones has a remote?
  • Next by Date: Correction: AVAudioPlayer with MPMediaItemPropertyAssetURL
  • Previous by thread: Re: possible to detect if headphones has a remote?
  • Next by thread: Re: AVAudioPlayer with MPMediaItemPropertyAssetURL
  • Index(es):
    • Date
    • Thread