Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Music player paused accidentally when the app is launching #112

Closed
AlexV525 opened this issue May 25, 2020 · 17 comments
Closed

Music player paused accidentally when the app is launching #112

AlexV525 opened this issue May 25, 2020 · 17 comments
Assignees
Labels
bug Something isn't working waiting for user test Working on it Working on it

Comments

@AlexV525
Copy link
Contributor

Flutter Version

My version : 1.17.1

Lib Version

My version : 1.6.0+4

Platform (Android / iOS / web) + version

Platform : Android (iOS not tested)
Device Model: OnePlus 8 Pro (IN2020) / OnePlus 6T (A6010)

Describe the bug

When a flutter app implemented this package (e.g. just import it), start the app will pause the current playing audio (Music that was playing).

Step to reproduce

  1. Add assets_audio_player: ^1.6.0+4 into pubspec.yaml.
  2. Play a song with some music player.
  3. Run the app.
  4. When the app start, the song was paused.
@florent37
Copy link
Owner

when you tell current playing audio, it's for example "youtube music player" ?

@AlexV525
Copy link
Contributor Author

Yes, just like the one in the screenshot.
Screenshot_20200526-003123__01

@florent37
Copy link
Owner

Ok thanks that's my next bug to fix !

@florent37 florent37 added the Working on it Working on it label May 26, 2020
@florent37
Copy link
Owner

found, it's because of the requestAudioFocus, used to pause the media player on phone call

@florent37
Copy link
Owner

maybe I can make this optional, like "requestAudioFocus: true" on open method (by default), which enable to listen audio focus & stop on phone call

setting it to false will solve your issue, but recieving a phone call will not pause the audio !

@florent37
Copy link
Owner

or maybe migrate to https://stackoverflow.com/questions/5948961/how-to-know-whether-i-am-in-a-call-on-android, to only pause on phone call :) I'll look for this

@florent37
Copy link
Owner

this solution requires runtime permission :/ it's not a good solution for the user

@AlexV525
Copy link
Contributor Author

found, it's because of the requestAudioFocus, used to pause the media player on phone call

This sounds good. How if we can requestAudioFocus only when we start the first play?

@florent37
Copy link
Owner

If we do this, it will stop the other media player at the start, like your qq music player

I think you'll need to make a choice,

  1. make this media player require focus (pause others players, intercept phone call state)

  2. Don't mind if audio focus : don't pause other players, but don't know if the phone is receiving a call

@AlexV525
Copy link
Contributor Author

  1. make this media player require focus (pause others players, intercept phone call state)

Am I missing something? I mean pause other players when the app which calling this package to play an audio. This behaviour is fine because it calls by user's request.

e.g. I'm playing some music with QQMusic, then I start my flutter app, choose an audio and try to play it, at that time it should stop my music and play the audio I requested.

@florent37
Copy link
Owner

Oh ok I see, I just have to move the request audio, sorry ^^ I'll do that today

@florent37
Copy link
Owner

I fixed this, can you try the ^1.6.2+5 ?

@florent37
Copy link
Owner

I close it but if this does not work, reopen it please :)

@AlexV525
Copy link
Contributor Author

Thanks for your rapid response! And it's been resolved through I tested with my devices.

@vinh-savvycom
Copy link

vinh-savvycom commented Feb 20, 2021

Hi @AlexV525 , current I'm using version assets_audio_player: ^2.0.13+8. But when I play a AssetsAudioPlayerGroup. Sound play normally but when I go to background and open app again. Sound auto stopped. I check log when I open app again see that:
D/AudioManager(16302): dispatching onAudioFocusChange(-1) to android.media.AudioManager@f3d4723com.github.florent37.assets_audio_player.stopwhencall.StopWhenCallAudioFocus$sam$i$android_media_AudioManager_OnAudioFocusChangeListener$0@682fee7

Please help me check it. Thanks

@kalismeras61
Copy link
Collaborator

@vinh-savvycom can you paste your open method here ?

@vinh-savvycom
Copy link

vinh-savvycom commented Feb 20, 2021

@kalismeras61 here is code init AssetsAudioPlayerGroup

AudioPlayer() {
    playerGroup = AssetsAudioPlayerGroup(
      updateNotification: (player, audios) async {
        return PlayerGroupMetas(
          title: currentSong.title,
          subTitle: currentSong.categoryName,
          image: MetasImage.network(
              getUrlFromServer(currentSong.thumb.path, currentSong.thumb.uuid)),
        );
      },
      respectSilentMode: true,
      showNotification: true,
      notificationStopEnabled: false,
      onNotificationPause: (player, audios) {
        togglePlay();
      },
      onNotificationPlay: (player, audios) {
        togglePlay();
      },
    );
  }

and here sample code add audio and play

Audio audio = Audio.network(
            getMediaURLFromServer(soundData.path, soundData.uuid),
            metas: Metas(
              title: song.title,
              album: song.categoryName,
              image: MetasImage.network(
                getUrlFromServer(song.thumb.path, song.thumb.uuid),
              ),
            ),
          );
          playerGroup.add(
            audio,
            volume: soundData.fileVolume / 100.0,
            loopMode: LoopMode.single,
          );

I used this command for play sound

playerGroup.playOrPause();

I have issue on Android real device and debug mode.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting for user test Working on it Working on it
Projects
None yet
Development

No branches or pull requests

4 participants