Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7586433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:25:43+00:00 2026-05-30T19:25:43+00:00

I have an audio player that I’m building using AVPlayer. Currently, I keep the

  • 0

I have an audio player that I’m building using AVPlayer.

Currently, I keep the player instance around and when I need to swap tracks (either from a manual selection or the track has reached the end) I create a new AVPlayerItem and I call replaceCurrentItemWithPlayerItem with the new item.

According to the docs, replaceCurrentItemWithPlayerItem is an asynchronous operation, so I also observe the currentItem key path of the player. When that gets called, I tell my player to play.

Here is the relevant code:

AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
[playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:CHStreamingAudioPlayer_PlayerItemStatusChangedContext];

if (!_player) {
    _player = [[AVPlayer alloc] initWithPlayerItem:playerItem]; 
    [_player addObserver:self forKeyPath:@"status"          options:NSKeyValueObservingOptionNew context:CHStreamingAudioPlayer_PlayerStatusChangedContext];
    [_player addObserver:self forKeyPath:@"currentItem"     options:NSKeyValueObservingOptionNew context:CHStreamingAudioPlayer_PlayerCurrentItemChangedContext];
} else {
    [_player replaceCurrentItemWithPlayerItem:playerItem];
}

And here is the key value observation callback:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if (context == CHStreamingAudioPlayer_PlayerCurrentItemChangedContext) {
        NSLog(@"Player's current item changed! Change dictionary: %@", change);
        if (_player.currentItem) {
            [self play]; //<---- doesn't get called
        }
    } else {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
}

On iOS 4.3.3 (and iOS 5) my key observation method is called but _player.currentItem is always nil. On 4.2.1 and 4.3.2 this property contains the actual value. This method is never called again. So in essence, replacing seems to always fail.

This seems like a bug, but perhaps I’m doing something wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:25:44+00:00Added an answer on May 30, 2026 at 7:25 pm

    I had this issue with iOS 5 (including 5.0.1). It used to work fine on iOS 4.x.

    There are two ways to workaround this, release and recreate your AVPlayer with the desired AVPlayerItems each time you need to swap tracks. Or, simply call replaceCurrentItemWithPlayerItem: on the main thread.

    I tried both options and they worked fine.

    Credits to: Apple Developer Forums

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an mp3 player that sends MCI commands to play pause/ff/rw/stop the audio
We have some raw voice audio that we need to distribute over the internet.
I have been working on a jquery plugin that uses a HTML5 audio player
So im building a chrome extension and I have placed an audio flash player
I'm writing an audio player using MediaPlayer that allows the user to skip the
Is it possible to have a Flash player that only plays the AAC audio
I have an audio player using NAudio and I would like to display a
I have an audio player toolbar activity that has a corresponding layout file. I
I need an embeddable audio player that will play wav files in IE, FF,
I have an intent that launches an Audio Player Intent, and plays an Audio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.