I want to play audio song from a URL, I implemented it successfully with AVPlayer
, but at some point it is not working fine.
Can we play an audio song from a URL with AVAudioPlayer
?
Which is better to play audio from a URL, providing all of the audio controls?
Sure you can.
Objective-C:
NSURL *url = [[NSURL alloc]initWithString:@"your string"];
AVPlayerItem *item = [[AVPlayerItem alloc]initWithURL:url];
AVPlayer *player = [[AVPlayer alloc]initWithPlayerItem:item];
[player play];
Swift:
let url = NSURL(string: "yourURL")
let item = AVPlayerItem(URL: url)
let p = AVPlayer(playerItem: item)
p.play()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.