Play MP3 Files with iPhone SDK

2019-01-10 19:40发布

what 's the easiest way to play a music file such as Mp3 with pause botton ? very very simple a button play and another button pause that music .. can you write that code !

8条回答
戒情不戒烟
2楼-- · 2019-01-10 20:32

well here is a good tutorial available.

The theme is

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audiofile.mp3", [[NSBundle mainBundle] resourcePath]]];

    NSError *error;
    AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    audioPlayer.numberOfLoops = -1;

[audioPlayer play];

and when you want to pause;

[audioPlayer pause];

hope this helps.

查看更多
走好不送
3楼-- · 2019-01-10 20:34

The Apple documentation here should have everything you need to know.

查看更多
登录 后发表回答