我使用此代码播放歌曲它不是播放文件夹或文件夹文件夹内的歌曲,但 Documents 目录除外。
NSString *songname=[NSString stringWithFormat"%@",songArray[songIndex]];
NSLog(@"songname:%@",songname);
NSString* saveFileName = songname;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:saveFileName];
NSURL *url = [[NSURL alloc] initFileURLWithPath: path];
self.audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
Best Answer-推荐答案 strong>
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent"github.mp4"];
NSURL *url1 = [[NSURL alloc] initFileURLWithPath: path];
avPlayer = [AVPlayer playerWithURL:url1] ;
[self.avplayer play];
关于ios - AVAudioPlayer 不播放文件夹内的歌曲?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/17720571/
|