gpt4 book ai didi

ios - avplayer 没有播放 URL

转载 作者:可可西里 更新时间:2023-11-01 03:07:07 24 4
gpt4 key购买 nike

我正在使用 avplayer 播放音频 url,但它不起作用,我不知道我哪里错了

NSString *radioURL = @"https://www.example.com";

radioPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:radioURL]] ;
// [radioPlayer seekToTime:kCMTimeZero];
NSLog(@"radio player %@",radioPlayer.currentItem);
[radioPlayer play];

如有任何帮助,我们将不胜感激。

最佳答案

我强烈推荐下面的代码来播放广播流:也请看看AVPlayer_Class

 -(void)Play{
NSString *radioURL = @"https://www.example.com"; //this url must valid
AVPlayer *player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:radioURL]];
self.songPlayer = player; //self.songPlayer is a globle object of avplayer
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[songPlayer currentItem]];
[self.songPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
}


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

if (object == songPlayer && [keyPath isEqualToString:@"status"]) {
if (songPlayer.status == AVPlayerStatusFailed) {
NSLog(@"AVPlayer Failed");

} else if (songPlayer.status == AVPlayerStatusReadyToPlay) {
NSLog(@"AVPlayerStatusReadyToPlay");
[self.songPlayer play];


} else if (songPlayer.status == AVPlayerItemStatusUnknown) {
NSLog(@"AVPlayer Unknown");

}
}
}

- (void)playerItemDidReachEnd:(NSNotification *)notification {

// code here to play next sound file

}

引用链接是 - Streaming mp3 audio with AVPlayer

关于ios - avplayer 没有播放 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22216393/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com