iphone - 如何在 iOS 设备上浏览和播放本地音频文件?

标签 iphone ios ipad file audio

我正在开发一个 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/

相关文章:

iphone - 使用 Objective C 根据经纬度搜索周边郊区

iphone - 如何查找访问量最高的 20 个项目并将其添加为收藏夹

ios - 无法在 tableViewcell 中设置 UILabel 填充

ios - 以编程方式在 Swift 中获取键盘框架

ios - 如何在 IOS 中将表值存储到核心数据实体中

ios - tvOS 应用内存问题 : How to resolve it?

ios - 当菜单弹出窗口可见时,UISplitViewController 会缩小左侧

iphone - Objective-C 编码准则

objective-c - 在单个 iOS View 中概括 UI 元素关系

iphone - iPad 中的最大应用程序内存限制?