1
我有一個應用程序包含三個按鈕,播放,暫停和停止。在viewDidLoad
我做到以下幾點:iOS AVAudioPlayer
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:songName ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
[playBtn addTarget:self action:@selector(playSong) forControlEvents:UIControlEventTouchUpInside];
[pauseBtn addTarget:self action:@selector(pauseSong) forControlEvents:UIControlEventTouchUpInside];
[stopBtn addTarget:self action:@selector(stopSong) forControlEvents:UIControlEventTouchUpInside];
的playSong功能是:
-(void) playSong
{
[player play];
}
如果我按下播放按鈕時,文件被加載,並保持按下約3秒鐘,然後在音樂開始播放。當按下播放按鈕時,是否有辦法讓背景音樂立即播放?