如何使用AVAudioPlayer在iPhone sdk中暂停和恢复同一首歌曲
我想暂停这首歌,然后在iphone中使用编程语言从这一点继续播放。当我尝试暂停歌曲时,我想再次开始播放我暂停的歌曲。它是如何编码的。是否有任何直接属性或建议任何代码可以解决我的问题如何使用AVAudioPlayer在iPhone sdk中暂停和恢复同一首歌曲,iphone,objective-c,avaudioplayer,Iphone,Objective C,Avaudioplayer,我想暂停这首歌,然后在iphone中使用编程语言从这一点继续播放。当我尝试暂停歌曲时,我想再次开始播放我暂停的歌曲。它是如何编码的。是否有任何直接属性或建议任何代码可以解决我的问题 -(void)playMusic { path=[[NSBundle mainBundle]pathForResource:@"01my song here" ofType:@"mp3"]; AVAudioPlayer *myAudio=[[AVAudioPlayer alloc]initWithCo
-(void)playMusic
{
path=[[NSBundle mainBundle]pathForResource:@"01my song here" ofType:@"mp3"];
AVAudioPlayer *myAudio=[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path ] error:nil];
self.audioPlayer=myAudio;
[myAudio release];
//audioPlayer.playing ;
[audioPlayer play];
}
-(void)stopMusic
{
[audioPlayer stop];
}
-(void)pauseMusic
{
[audioPlayer pause];// here it is just stopping, how can I start where I sttoped.
}
谢谢,,
马丹·莫汉 是的,它工作,但当我选择停止按钮,再次播放按钮,然后它应该开始从开始。我已经做了,但现在添加播放器=零在该方法中,现在它的工作良好。非常感谢。
if(!player){
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/grabbag.m4a"];
NSLog(@"Path to play: %@", resourcePath);
NSError* err;
//Initialize our player pointing to the path to our resource
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath] error:&err];
if( err ){
//bail!
NSLog(@"Failed with reason: %@", [err localizedDescription]);
}
else{
//set our delegate, flip the button and let the magic happen
player.delegate = self;
[self flipButton:YES];
[player play];
}
}
else{
//If the player exists here, then we're already playing.
NSLog(@"Resuming playback!");
[player play];
[self flipButton:YES];
}