Unable to play .wav file Using AVPlayer

橙三吉。 提交于 2019-12-13 01:02:44

问题


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:


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];    


来源:https://stackoverflow.com/questions/7848439/unable-to-play-wav-file-using-avplayer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!