How to play a music file using URL link in iPhone?

后端 未结 5 743
无人共我
无人共我 2020-12-13 05:12

I want to play a music file using URL Link in the iPhone. But when I use the below code I am getting error I am not getting where I am going wrong. Can anyone Correct me?

5条回答
  •  醉话见心
    2020-12-13 05:45

    This should work:

    NSURL *url = [NSURL URLWithString:@"<#Live stream URL#>];
    
    // You may find a test stream at .
    
    self.playerItem = [AVPlayerItem playerItemWithURL:url];
    
    //(optional) [playerItem addObserver:self forKeyPath:@"status" options:0 context:&ItemStatusContext];
    
    self.player = [AVPlayer playerWithPlayerItem:playerItem];
    
    self.player = [AVPlayer playerWithURL:<#Live stream URL#>];
    
    //(optional) [player addObserver:self forKeyPath:@"status" options:0 context:&PlayerStatusContext];
    

    Use the following code to play the music:

    [self.player play];

提交回复
热议问题