AVAUdioPlayer - changing current URL

前端 未结 2 1321
无人共我
无人共我 2020-12-17 05:06

In my audio player app, if I hit the fast forward button - the player must find the next song in the playlist and play it. What I do is I get the URL from the next song, and

2条回答
  •  感情败类
    2020-12-17 05:30

    For playing more than one URL, or effectively changing the URL, use the subclass AVQueuePlayer.

    AVQueuePlayer is a subclass of AVPlayer you use to play a number of items in sequence.

    Example:

    NSString *fooVideoPath = [[NSBundle mainBundle] pathForResource:@"tommy" ofType:@"mov"];
    NSString *barVideoPath = [[NSBundle mainBundle] pathForResource:@"pamela" ofType:@"mp4"];
    
    AVPlayerItem *fooVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:fooVideoPath]];
    AVPlayerItem *barVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:barVideoPath]];
    
    self.queuePlayer = [AVQueuePlayer queuePlayerWithItems:[NSArray arrayWithObjects:fooVideoItem, barVideoItem,nil]];
    [self.queuePlayer play];
    
    // things happening...
    
    [self.queuePlayer advanceToNextItem];
    

提交回复
热议问题