로컬 .wav 파일 재생에 문제가 있습니다. 내 AVPlayerStatus
은 0
을 인쇄하고 있습니다. 나는 그것이 재생 준비가되어 있지 않다는 것을 의미한다고 가정하고 있습니다. 알아낼 수는 없지만 AVPlayer와 관련이있는 것은 처음 사용하는 것이므로 간단 할 것 같습니다. 나는 어떤 도움을 주셔서 감사합니다. 코드는 다음과 같습니다.로컬 파일 용 AVPlayerStatus가 준비되지 않았습니다.
나는 소리가 재생되지 않는다고 덧붙여 야합니다!
-(void) playWordSound:(UILabel *)label
{
NSString *path;
switch (label.tag)
{
case 1:
path = [[NSBundle mainBundle] pathForResource:@"humpty" ofType:@"wav"];
break;
case 2:
path = [[NSBundle mainBundle] pathForResource:@"dumpty" ofType:@"wav"];
break;
case 3:
path = [[NSBundle mainBundle] pathForResource:@"saty" ofType:@"wav"];
break;
case 4:
path = [[NSBundle mainBundle] pathForResource:@"on 2" ofType:@"wav"];
break;
case 5:
path = [[NSBundle mainBundle] pathForResource:@"a 3" ofType:@"wav"];
break;
case 6:
path = [[NSBundle mainBundle] pathForResource:@"wall" ofType:@"wav"];
break;
}
NSURL *url = [NSURL fileURLWithPath:path];
AVQueuePlayer *player;
static const NSString *ItemStatusContext;
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
[playerItem addObserver:self forKeyPath:@"status" options:0 context:&ItemStatusContext];
player = [AVPlayer playerWithPlayerItem:playerItem];
NSLog(@"%d",player.status);
[player play];
}
- (void)playerItemDidReachEnd:(NSNotification *)notification {
NSLog(@"Sound finished");
}
AVAsset으로 초기화하면 해결되었습니다! 도와 주셔서 정말 감사합니다! –
기꺼이 도와 드리겠습니다. 건배! – MiguelB