【问题标题】:Playing a sound from local Documents从本地文档播放声音
【发布时间】:2014-06-08 00:43:14
【问题描述】:

我正在尝试从手机上的本地文档中获取 mp3。但我无法让它工作。

如果我像这样直接将 mp3 添加到项目中,它可以工作。

NSURL *soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Sound" ofType:@"mp3"]];

但是假设我在我尝试过的文档中有 Sound.mp3:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *strPointSound = [documentsDirectory stringByAppendingPathComponent:
                  [NSString stringWithFormat: @"/tours/media/%@", self.point.pointSound] ];


NSURL *soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:strPointSound ofType:@"mp3"]];

self.point.pointSound 是“Sound.mp3”。

亲切的问候。

【问题讨论】:

    标签: ios nsurl nsdocumentdirectory


    【解决方案1】:

    你可以试试

    NSURL *soundURL = [NSURL fileURLWithPath:strPointSound];
    

    【讨论】:

      【解决方案2】:

      改变

      NSURL *soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:strPointSound ofType:@"mp3"]];

      NSURL *soundURL = [NSURL fileURLWithPath:strPointSound];

      因为 Document 文件夹不是你的包的一部分,所以你不需要它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-18
        • 2011-05-25
        • 2017-04-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多