Giter Club home page Giter Club logo

Comments (6)

ryanheise avatar ryanheise commented on June 14, 2024

Hi @snaeji

Glad you like the plugin!

It's actually a bit of a mystery how to control what gets shown on the Android lock screen. The code responsible is in AudioService.java in the buildNotification method if you are curious.

However, let's just check the basic things first. You control what buttons you want to display in each state when you call AudioServiceBackground.setState and pass in a list of MediaControl objects. Furthermore you can control which subset of those buttons are shown in the compact view with androidCompactActions. Can you tell me what values you're passing into setState on pause?

from audio_service.

hacker1024 avatar hacker1024 commented on June 14, 2024

It's actually a bit of a mystery how to control what gets shown on the Android lock screen. The code responsible is in AudioService.java in the buildNotification method if you are curious.

I assume ROMs that show lock screen controls like these will use the MediaSession, and choose actions flagged available in the PlaybackState.

from audio_service.

ryanheise avatar ryanheise commented on June 14, 2024

That's also what I would like to assume, but I have seen some strange behaviours despite these flags being set. In any case, the plugin does automatically set these flags based on the MediaControl objects passed into AudioServiceBackground.setState.

from audio_service.

snaeji avatar snaeji commented on June 14, 2024

I have found a workaround for the problem after a little debugging.

The problem is:

  1. Pressing pause on the lockscreen calls the pause function an the icon changes to play
  2. Pressing play on the lockscreen calls the pause function and nothing happens.

My workaround:

  play() async {
    await _audioPlayer.play(href);
    newSubscription = _audioPlayer.onPlayerStateChanged
        .where((state) => state == AudioPlayerState.PLAYING)
        .listen((state) {
      duration = _audioPlayer.duration;
      MediaItem mediaItem = MediaItem(
          id: 'xx',
          album: xx,
          title: xx,
          artUri: xx,
          duration: _audioPlayer?.duration?.inSeconds ?? 200);

      AudioServiceBackground.setMediaItem(mediaItem);
      AudioServiceBackground.setState(
        controls: [rewindControl, pauseControl, forwardControl, stopControl],
        basicState: BasicPlaybackState.playing,
        updateTime: DateTime.now().millisecondsSinceEpoch,
        position: position.inSeconds,
      );
    });
  }

  void pause() {
    if (AudioServiceBackground.state.basicState == BasicPlaybackState.paused) {
      play();
    }
    else {
    _audioPlayer.pause();

    AudioServiceBackground.setState(
        controls: [playControl, stopControl],
        basicState: BasicPlaybackState.paused,
        updateTime: DateTime.now().millisecondsSinceEpoch,
        position: position.inSeconds );
    }
  }

Previous code that caused the issue:

  play() async {

    await _audioPlayer.play(href);

    newSubscription = _audioPlayer.onPlayerStateChanged
        .where((state) => state == AudioPlayerState.PLAYING)
        .listen((state) {
      duration = _audioPlayer.duration;
      MediaItem mediaItem = MediaItem(
          id: 'xx',
          album: xx,
          title: xx,
          artUri: xx,
          duration: _audioPlayer?.duration?.inSeconds ?? 200);

      AudioServiceBackground.setMediaItem(mediaItem);
      AudioServiceBackground.setState(
        controls: [rewindControl, pauseControl, forwardControl, stopControl],
        basicState: BasicPlaybackState.playing,
        updateTime: DateTime.now().millisecondsSinceEpoch,
        position: position.inSeconds,
      );
    });
  }

  void pause() {

    _audioPlayer.pause();

    AudioServiceBackground.setState(
        controls: [playControl, stopControl],
        basicState: BasicPlaybackState.paused,
        updateTime: DateTime.now().millisecondsSinceEpoch,
        position: position.inSeconds);
  }

from audio_service.

snaeji avatar snaeji commented on June 14, 2024

Sorry for this issue! The fault was on my end. I wasn't settings a boolean for play and pause for:
(MediaButton button) => player.playPause()

from audio_service.

github-actions avatar github-actions commented on June 14, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service.

from audio_service.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.