Unable to play .wav file Using AVPlayer

2019-08-02 13:27发布

I have some wav files and they completely working with MPMoviePlayer. but not working with AVPlayer. For some reason I have changed my player to AVPlayer. But after implementation I found that some of my audio files are not working with AVPlayer.I have used apples sample code of AVPlayer. Any suggestion would be appreciated.

1条回答
混吃等死
2楼-- · 2019-08-02 14:22

Does other format work ? Perhaps it's a coding problem.

Anyway. If your WAV files are ok, import them into iTunes, convert them once (right click on the file into the library), and convert the converted one back to wav (same method). You should then have an iPhone compatible WAV file.

If that does not work, that should be a coding problem :-)

Try :

NSString* path = [[NSBundle mainBundle] pathForResource:soundfileName ofType:fileType];
if ([[NSFileManager defaultManager] fileExistsAtPath:path] == NO) NSLog (@"No file");

AVPlayer* player = [AVPlayer playerWithURL:[NSURL fileURLWithPath:path]];
[player play];    
查看更多
登录 后发表回答