gpt4 book ai didi

ios - 如何在iOS中从url播放mp3文件?

转载 作者:行者123 更新时间:2023-12-01 18:49:51 24 4
gpt4 key购买 nike

我正在尝试播放位于远程服务器上某处的mp3文件。我有该音乐文件的url我已经尝试使用AVAudioPlayerAVPlayer播放它,但是我无法播放mp3文件。请告诉我如何播放mp3文件。

播放音乐的代码:

 NSString *aSongURL = [NSString stringWithFormat:@"http://megdadhashem.wapego.ru/files/56727/tubidy_mp3_e2afc5.mp3"];
// NSLog(@"Song URL : %@", aSongURL);

AVPlayerItem *aPlayerItem = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:aSongURL]];
AVPlayer *anAudioStreamer = [[AVPlayer alloc] initWithPlayerItem:aPlayerItem];
[anAudioStreamer play];

// Access Current Time
NSTimeInterval aCurrentTime = CMTimeGetSeconds(anAudioStreamer.currentTime);

// Access Duration
NSTimeInterval aDuration = CMTimeGetSeconds(anAudioStreamer.currentItem.asset.duration);

请告诉我我该怎么做?

最佳答案

尝试下面的代码。

NSURL *url = [NSURL URLWithString:@"http://megdadhashem.wapego.ru/files/56727/tubidy_mp3_e2afc5.mp3"];
self.playerItem = [AVPlayerItem playerItemWithURL:url];
self.player = [AVPlayer playerWithPlayerItem:playerItem];
self.player = [AVPlayer playerWithURL:url];
[self.player play];

关于ios - 如何在iOS中从url播放mp3文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32043011/

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