Skip to content

AudioService.pause return a Exception  #391

@yagoliveira92

Description

@yagoliveira92

Which API doesn't behave as documented, and how does it misbehave?
The AudioService.pause() return a Exception in call with button.

Minimal reproduction project
The complete project is in https://github.com/yagoliveira92/radio-basic, but the call is:

    return FloatingActionButton(
      backgroundColor: mainColor,
      onPressed: () => buttonChange(playing),
      child: Container(
          width: 120,
          margin: EdgeInsets.all(7.5),
          decoration: BoxDecoration(
              shape: BoxShape.circle,
              border: Border.all(color: Color(0xFF055D6F), width: 3.2)),
          child: AnimatedIcon(
            icon: AnimatedIcons.pause_play,
            progress: _animateIcon,
            color: Color(0xFF055D6F),
            size: 35,
          )),
    );

The buttonChange call with this:

  void buttonChange(bool playing) {
    if (playing == AudioService.playbackState.playing) {
      _animationController.forward();
      player.pause();
    } else {
      _animationController.reverse();
      player.play();
    }
  }

and the player.pause() is that:

pause() => AudioService.pause();

To Reproduce (i.e. user steps, not code)
Click in pause button after the music start

Error messages

Exception has occurred.
PlatformException (PlatformException(error, Attempt to invoke virtual method 'android.support.v4.media.session.MediaControllerCompat$TransportControls android.support.v4.media.session.MediaControllerCompat.getTransportControls()' on a null object reference, null))

Full log:

E/MethodChannel#ryanheise.com/audioService( 2508): Failed to handle method call
E/MethodChannel#ryanheise.com/audioService( 2508): java.lang.NullPointerException: Attempt to invoke virtual method 'android.support.v4.media.session.MediaControllerCompat$TransportControls android.support.v4.media.session.MediaControllerCompat.getTransportControls()' on a null object reference
E/MethodChannel#ryanheise.com/audioService( 2508): 	at com.ryanheise.audioservice.AudioServicePlugin$ClientHandler.onMethodCall(AudioServicePlugin.java:488)
E/MethodChannel#ryanheise.com/audioService( 2508): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/MethodChannel#ryanheise.com/audioService( 2508): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#ryanheise.com/audioService( 2508): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/MethodChannel#ryanheise.com/audioService( 2508): 	at android.os.MessageQueue.nativePollOnce(Native Method)

Expected behavior
Pause the music =D

Screenshots
This project is OpenSource. I create a Radio App to help others devs to make yours with the minimal design and usability. I used another version with AudioService and I trying update. The code is in https://github.com/yagoliveira92/radio-basic/tree/develop

Runtime Environment (please complete the following information if relevant):
Device: Google Pixel 2 (Genymotion) and Redmi 6A
OS: Android 9

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.4, on Linux, locale pt_BR.UTF-8)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.46.1)
[✓] Connected device (1 available)

• No issues found!

Additional context
All content show in my repository: https://github.com/yagoliveira92/radio-basic/tree/develop

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions