Automattic / pocket-casts-android

Pocket Casts Android 🎧
https://forums.pocketcasts.com
Mozilla Public License 2.0
2.58k stars 222 forks source link

Check if Android correctly handles play/pause for BT devices #149

Open mchowning opened 2 years ago

mchowning commented 2 years ago

User report:

I have a 2019 audi e-tron where I use android auto to play pocketcasts.

When I use youtube music, I'm able to pause and unpause the music with the steering wheel button. However, with pocketcasts, I can only pause it. It does not resume playing when I press the button again on the steering wheel; I have to resume playback by pressing a button on the screen.

Russell stated:

I suspect what's happening here is that the button on the steering wheel always sends a pause event. On iOS we handle this like so:

commandCenter.playCommand.addTarget { [weak self] _ -> MPRemoteCommandHandlerStatus in
    guard let strongSelf = self, let _ = strongSelf.currentEpisode() else { return .noActionableNowPlayingItem }

    if Settings.legacyBluetoothModeEnabled() {
        FileLog.shared.addMessage("Remote control: playCommand, treating as play (Legacy BT Mode is on)")
        if !strongSelf.playing() { strongSelf.play() }
    }
    else if let lastPlayTime = UserDefaults.standard.object(forKey: Constants.UserDefaults.lastPlayEvent) as? Date, fabs(lastPlayTime.timeIntervalSinceNow) < 10.seconds {
        // iOS will sometimes issue two remotePlay commands, so if it's been less than 10 seconds since the last one, just play don't try to playPause
        FileLog.shared.addMessage("Remote control: playCommand, treating as play")
        if !strongSelf.playing() { strongSelf.play() }
    }
    else {
        if strongSelf.playingOverAirplay() {
            // during handoff iOS will call us to play even if we already are, so honour that here
            FileLog.shared.addMessage("Remote control: playCommand, treating as play because playing over AirPlay")
            if !strongSelf.playing() { strongSelf.play() }
        }
        else {
            // we hook play up to play/pause because that's how some headphones/car stereos do it instead of sending distinct play/pause events
            FileLog.shared.addMessage("Remote control: playCommand, treating as playPause")
            strongSelf.playPause()
        }
    }

I realise this is for the play command on iOS, but it might be worth checking the Android app to see if it doesn't something similar to handle this case?

joashrajin commented 10 months ago

I noticed in my Mazda CX-30 using Android Auto that PocketCasts treats the unmute command differently than other audio apps. It seems if I mute then unmute it will pause then resume. But if I wait a bit and then unmute, it will ignore the unmute request. There is no way to get the podcast going again from the car media buttons, I have to hit play in the Android Auto UI. This is different to how both Google Podcasts and Spotify handle the same button. Where unmute maybe 5 mins after muting will resume what I was listening to. A use case for this would be navigating some busy intersections where I want to pause the show to focus, and then unpause the show when I’m back crusing.

7524229-zd-a8c

joashrajin commented 10 months ago

6533688-zd-a8c

thabotswana commented 4 months ago

Another report here: https://forums.pocketcasts.com/forums/topic/android-auto-pocketcasts-treats-unmute-differently-to-other-audio-apps/?view=all#post-4222

dericleeyy commented 4 months ago

some debug logs are provided in 8368631-zd-a8c