【问题标题】:How to use MPMediaPickerController with Local Files in Documents Directory? [closed]如何将 MPMediaPickerController 与文档目录中的本地文件一起使用? [关闭]
【发布时间】:2012-07-06 04:45:31
【问题描述】:

我希望能够在 Documents 目录中下载的本地文件上使用 MPMediaPickerController。 但是,没有选项可以设置控制器查看的文件的来源,当然默认为 iPod 音乐库。

是否有任何方法可以加载本地文件,或者是否有任何替代库可用于提供媒体选择功能?还是我必须在这里重新发明轮子:(

【问题讨论】:

    标签: ios open-source media-player


    【解决方案1】:

    您可能想看看AVAudioPlayer,因为 MPMediaPickerController 是一个旨在播放仅存储在 iTunes 媒体文件夹中的音乐的类。从 doc 目录播放媒体也很容易:

    NSString *soundFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]stringByAppendingPathComponent:@"mySong.m4a"];
    NSURL *fileURL = [NSURL URLWithString:soundFilePath];
    NSError *error;
    AVAudioPlayer* audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
    if(!error){
        audioPlayer.delegate = self;
        [audioPlayer play];
    }else{
        NSLog(@"Error loading clip: %@", [error localizedDescription]); 
    }
    

    【讨论】:

    • 不过,您需要制作自己的用户界面来浏览/选择文件。
    • 谢谢,我选择了一个基于 AVAudioPlayer 的开源音乐播放器!
    猜你喜欢
    • 1970-01-01
    • 2018-01-17
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 2012-09-16
    • 1970-01-01
    • 2014-07-30
    相关资源
    最近更新 更多