我在播放本地.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