开发者

ios Music player [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, vi开发者_运维问答sit the help center. Closed 11 years ago.

Hi I am working on an Alarm Clock app.. I am using MPMediaPickerController class,using it I was able to pick and the mp3 file but not able to get the path of the file to play when UINotification gets called. Can anyone suggest something..??

Thanks


You're not given the path, you're given a URL, in such a form as AVFoundation should understand it. I think part of the reason you never get a path is to protect DRM content. Anyway, your delegate should drill the returned MPMediaItemCollection down to the MPMediaItem you want, you can then use valueForProperty to get the suitable URL.

Example code to play whatever is selected in an MPMediaPickerController immediately (typed for the first time here, please comment if I've made any errors):

// delegate method, to receive the result of the MPMediaPickerController
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker 
  didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
    // use the first item in the collection
    MPMediaItem *item = [[mediaItemCollection items] objectAtIndex:0];

    // get the URL to the MP3
    NSURL *URL = [item valueForProperty:MPMediaItemPropertyAssetURL];

    // URL uses a proprietary scheme, but AVFoundation understands it, so...
    AVAudioPlayer *player = [[AVAudioPlayer alloc] 
                    initWithContentsOfURL:URL error:NULL];
    [player play];
    /* NB: player will leak. Do something more sensible in your code */
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜