MPNowPlayingInfoCenter always in playing state
Asked Answered
N

2

9

I have my MPNowPlayingInfoCenter up and running but one problem remains. regardless of my actual player state the MPNowPlayingInfoCenter is always "playing" and displays the pause button. When pressed it fires the pause event.

When my player changes state, for example to paused, i update the MPNowPlayingInfoCenter via the MPNowPlayingInfoPropertyPlaybackRate key.

Is there any other way to set the MPNowPlayingInfoCenter state to paused?

Any hints appreciated!

Naquin answered 10/5, 2014 at 15:58 Comment(0)
N
0

Found out the issue was when a second source of audio output was playing while my included media player was controlled via nowplayingcenter it somehow ignored my manually set playback rate and detected audio playing.

So the solution for me was to pause the second audio as well. In my situation this was possible but i don't know how to overcome this when the second audio is critical for the app. I'll happily accept any answer which solves this issue more elegantly.

Naquin answered 16/6, 2014 at 11:47 Comment(4)
I ran into a similar issue. So I have a FeedViewController with many videos but it doesn't play audio which are always playing. If you select one of the videos in the FeedViewController, a PlayerViewController appears and plays the full video with audio. I noticed that if I did not pause every video in FeedViewController before going to PlayerViewController, then the "play/pause" button would not update accordingly. Is there a way you think to make this work without pausing the videos inside of PlayerViewController in my case?Weak
I posted a question and my UPDATE in the question shows a solution similar to yours --- but still not perfect in my case. : ) #43282923Weak
I think that the underlying problem is that iOS tracks audio playback under the hood and detects if you still play. If you use audio regular this makes sense as you only need one song for example at a time but with muted audio in the background this messes things up. I don't think there will a perfect solution as you don't get 100% manual control over the now playing center.Perspiratory
I see what you mean, any suggestions though? The audio has to be muted in the background or maybe I can have videos that don't have audio there.Weak
M
0

Try this:

 NSMutableDictionary *currentlyPlayingTrackInfo = [NSMutableDictionary dictionaryWithCapacity:7];
 currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @((Float64)[player currentTime]);
    if (!SYSTEM_VERSION_OF_DEVICE_LESS_THAN(@"7.0"))
    {
        currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyPlaybackRate] = [NSNumber numberWithDouble:_isHere == NO?1:0];
    }
    else
    {
        currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyPlaybackRate] = [NSNumber numberWithDouble:1];
    }
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:currentlyPlayingTrackInfo];
Metempsychosis answered 12/5, 2014 at 4:29 Comment(2)
Sorry for the late response. I'm having trouble using your code. What is the _isHere variable (current player state?) and why is the playbackRate for Versions < 7.0 always set to 1. Besides that the InfoCenter still always displays a "playing" state.Perspiratory
I think setting MPNowPlayingInfoPropertyPlaybackRate is on the right track but there's definitely more to solving this problem.Carbylamine
N
0

Found out the issue was when a second source of audio output was playing while my included media player was controlled via nowplayingcenter it somehow ignored my manually set playback rate and detected audio playing.

So the solution for me was to pause the second audio as well. In my situation this was possible but i don't know how to overcome this when the second audio is critical for the app. I'll happily accept any answer which solves this issue more elegantly.

Naquin answered 16/6, 2014 at 11:47 Comment(4)
I ran into a similar issue. So I have a FeedViewController with many videos but it doesn't play audio which are always playing. If you select one of the videos in the FeedViewController, a PlayerViewController appears and plays the full video with audio. I noticed that if I did not pause every video in FeedViewController before going to PlayerViewController, then the "play/pause" button would not update accordingly. Is there a way you think to make this work without pausing the videos inside of PlayerViewController in my case?Weak
I posted a question and my UPDATE in the question shows a solution similar to yours --- but still not perfect in my case. : ) #43282923Weak
I think that the underlying problem is that iOS tracks audio playback under the hood and detects if you still play. If you use audio regular this makes sense as you only need one song for example at a time but with muted audio in the background this messes things up. I don't think there will a perfect solution as you don't get 100% manual control over the now playing center.Perspiratory
I see what you mean, any suggestions though? The audio has to be muted in the background or maybe I can have videos that don't have audio there.Weak

© 2022 - 2024 — McMap. All rights reserved.