我正在开发一个 iPhone 应用程序,我需要为用户提供便利,让他/她能够选择保存在设备上的音频文件,并能够在我的应用程序中播放它们。请给我权利方向进行。 谢谢
最佳答案
你必须为此使用 MPMediaPickerControllerDelegate。
//in your .h file include the MPMediaPickerControllerDelegate
//in your .m file
- (IBAction) showMediaFilesPressed : (id) sender
{
MPMediaPickerController *picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
picker.delegate = self;
picker.allowsPickingMultipleItems = NO;
picker.prompt = NSLocalizedString(@"AddSongsPrompt", @"Prompt to user to choose some songs to play");
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated:YES];
[self presentModalViewController: picker animated: YES];
[picker release];
}
这将为您提供设备上列出的所有媒体文件。要播放这些文件,您可以在其委托(delegate)方法中为此编写代码。
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
//play your file here
}
本文可能对您有更多帮助。 http://oleb.net/blog/2009/07/the-music-player-framework-in-the-iphone-sdk/
关于iphone - 如何在 iOS 设备上浏览和播放本地音频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7117550/