Note that there are some explanatory texts on larger screens.

plurals
  1. POAVPlayer not forwarding streaming track in background
    primarykey
    data
    text
    <p>I'm having an issue with AVPlayer not <strong>playing</strong> in the background. </p> <p>Here's the details:</p> <p>I have an AVPlayer object and an AVPlayerItem as an instance variable of my view controller to stream music from links stored in the NSMutableArray, <em>linkArray</em>. When the user taps a track a track in a UITableView, both objects are instantiated like so:</p> <pre><code>musicPlayerItem = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:[linkArray objectAtIndex:indexPath.row]]]; player = [[AVPlayer alloc] initWithPlayerItem:musicPlayerItem]; </code></pre> <p>...And it plays perfectly. Whenever the track finishes while the app is <strong>active</strong> it'll skip fine, or when I manually trigger the app to skip track (whether it's active or backgrounded). But, when the app is in the background (including when the device is locked) it will not play the next track when it skips.</p> <p>So, it skips to the next track on its own but doesn't play it. I either have to make the app active again or invoke the playing (via the headphone controls or the system-wide music controls).</p> <p>Here is the code for the skipTrack method that is called both when manually invoked or by the system when the song reaches the end of the track:</p> <pre><code> if (nowPlaying == [linkArray count]-1) { nowPlaying = 0; musicPlayerItem = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:[linkArray objectAtIndex:0]]]; player = [[AVPlayer alloc] initWithPlayerItem:musicPlayerItem]; } else { NSLog(@"NowPlaying (before increment: %i", nowPlaying); //If not, increment nowPlaying by one and play nowPlaying++; NSLog(@"NowPlaying (after increment: %i", nowPlaying); musicPlayerItem = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:[linkArray objectAtIndex:nowPlaying]]]; player = [[AVPlayer alloc] initWithPlayerItem:musicPlayerItem]; } </code></pre> <p>Really hope someone can help me with </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload