Audio file not working on device but it is working on simulator

让人想犯罪 __ 提交于 2019-12-02 06:32:13
Paras Joshi

try this code...

NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];

first check the file is stored in your project folder or not and also that variable is not nil.

Also Check Out this Link play-mp3-files-with-iphone-sdk

And this tutorial how-to-play-audio-and-video-in-iphone

UPDATE:

MPMoviePlayerViewController *Mpplayer =[[MPMoviePlayerViewController alloc] initWithContentURL: [url standardizedURL]];
Mpplayer.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;  
[self presentModalViewController:Mpplayer animated:YES];
[[Mpplayer moviePlayer] play];

First add AVFoundation.framework and add below code.

in .h file

#import <AVFoundation/AVFoundation.h>

and .m file

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