이 라인에서
appDelegate.audioPlayer = [[AVPlayer alloc] init];
당신은 새로운 Avplayer를 할당하고 시작하는 것 같습니다. 따라서 "재생하지 않는"결과를 얻는 것은 놀라운 일이 아닙니다. 그 줄을 남기십시오.
문제
iOS 장치에 노래 테이블 뷰가 있고 행을 선택하면 Avplayer가 선택한 노래를 재생하기 시작하는 새로운보기로 푸시됩니다. 이제 돌아가서 다른 행을 선택하면 앱이 새 노래를 재생하기 시작하면서 이미 실행중인 노래를 계속 연주합니다.
편집 : 노래가 재생되는 경우에도 ViewDidload 메소드에 넣으면 항상 "재생되지 않는"출력이 있기 때문에 성공하지 않고 이와 같은 속도 값을 사용하려고 시도했습니다.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
appDelegate = (SimpleTableAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.audioPlayer = [[AVPlayer alloc] init];
if (appDelegate.audioPlayer.rate == 0.0f)
{
NSLog(@"not playing");
} else {
NSLog(@"already playing");
}
}
해결책
이 라인에서
appDelegate.audioPlayer = [[AVPlayer alloc] init];
당신은 새로운 Avplayer를 할당하고 시작하는 것 같습니다. 따라서 "재생하지 않는"결과를 얻는 것은 놀라운 일이 아닙니다. 그 줄을 남기십시오.
다른 팁
Avplayer는 a rate
플로트로 재생 속도를 나타내는 속성. 0.0f
중지를 나타냅니다. 그만큼 play
그리고 stop
메소드는 단지 변경됩니다 rate
재산.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
appDelegate = (SimpleTableAppDelegate *)[[UIApplication sharedApplication] delegate];
//Stop potential existing audioPlayer prior to creating new player
[appDelegate.audioPlayer stop];
//Create new audio player
appDelegate.audioPlayer = [[AVPlayer alloc] init];
}