我正在创建音乐播放器,并且已经具有歌曲的相对路径,即“/Users/username/Music/song.mp3”,我的代码是这样
NSURL * localURL = [NSURL URLWithString:audioPath];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:localURL];
self.audioPlayer = [[AVPlayer alloc] initWithPlayerItem : playerItem];
self.isPlaying = @"false";
[self.audioPlayer play];
但是我的macOs应用程序没有播放任何内容,并且song.mp3可以在iTunes上播放。
最佳答案
NSURL * localURL = [NSURL URLWithString:audioPath];
^^^^^^^^^^^^^
应该
NSURL * localURL = [NSURL fileURLWithPath:audioPath];
^^^^^^^^^^^^^^^
Refer to my original post
关于objective-c - 如何在macOS objective-c 中播放本地文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42049409/