如何在我的iPhone应用程序中访问iPod库 [英] How can I access iPod Library in my iPhone app
本文介绍了如何在我的iPhone应用程序中访问iPod库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何访问我的iPhone应用程序中的iPod库,例如在播放时...像Gameloft游戏中的音乐或用户Photos.app中的幻灯片放映一样,向用户播放音乐?
How access iPod Library in my iPhone app, like to the user listem music when is playing... like in the gameloft games, or the slide show from the Photos.app ?
推荐答案
- (void)addMusicBtnAction{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
mediaPicker.delegate = self;
//mediaPicker.prompt = @"Select Audio";
mediaPicker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");
for (UIWindow* window in [UIApplication sharedApplication].windows) {
NSArray* subviews = window.subviews;
if ([subviews count] > 0)
for (UIAlertView *alrt in subviews) {
if ([alrt isKindOfClass:[UIAlertView class]]){
if (alrt.tag == 10020) {
[alrt dismissWithClickedButtonIndex:0 animated:YES];
}
}
}
}
[self presentModalViewController:mediaPicker animated:YES];
//[mediaPicker release];
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
NSArray * SelectedSong = [mediaItemCollection items];
if([SelectedSong count]>0){
MPMediaItem * SongItem = [SelectedSong objectAtIndex:0];
NSURL *SongURL = [SongItem valueForProperty: MPMediaItemPropertyAssetURL];
NSString *str = [NSString stringWithFormat:@"%@",SongURL];
appDelegate.musicFilePath = str;
//NSLog(@"Audio Loaded");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Your audio has been selected" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil, nil];
alert.tag = 78787878;
[alert show];
// [alert release];
}
[self dismissModalViewControllerAnimated: YES];
}
// Responds to the user tapping done having chosen no music.
- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker {
[self dismissModalViewControllerAnimated: YES];
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque animated:YES];
}
这篇关于如何在我的iPhone应用程序中访问iPod库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文