2014-04-23 34 views
0

我試圖從手機上的本地文件中獲取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」。

親切的問候。

回答

2

變化

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

NSURL *soundURL = [NSURL fileURLWithPath:strPointSound];

因爲文件夾是不是你的包的一部分,所以你做不需要它。

1

,您可以嘗試

NSURL *soundURL = [NSURL fileURLWithPath:strPointSound];