Tôi gặp sự cố khi phát lại tệp .wav cục bộ. My AVPlayerStatus
đang in 0
, mà tôi giả định có nghĩa là nó chưa sẵn sàng để chơi. Tôi không thể hình dung ra nhưng đã nói rằng, đây là lần đầu tiên tôi cố gắng sử dụng bất cứ điều gì để làm với AVPlayer vì vậy nó có thể là một cái gì đó đơn giản. Tôi đánh giá cao sự giúp đỡ nào. Đây là mã:AVPlayerStatus cho tệp cục bộ chưa sẵn sàng
tôi nên thêm âm thanh của mình không phát!
-(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");
}
Khởi tạo như một AVAsset đã sửa nó! Cảm ơn rất nhiều vì sự giúp đỡ của bạn! –
Vui vì tôi có thể giúp. Chúc mừng! – MiguelB