ios – avplayer没有播放网址

ios – avplayer没有播放网址,第1张

概述我正在使用avplayer播放音频网址,但它无法正常工作,我不知道我错在哪里 NSString *radioURL = @"https://www.example.com";radioPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:radioURL]] ;// [radioPlayer seekToTime:kCMTimeZero] 我正在使用avplayer播放音频网址,但它无法正常工作,我不知道我错在哪里
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没有播放网址全部内容,希望文章能够帮你解决ios – avplayer没有播放网址所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1100051.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存