Code Monkey home page Code Monkey logo

smtc_windows's Introduction

SMTC_Windows

pub package

Windows SystemMediaTransportControls implementation for Flutter. This is the windows equivalent of android's audio_session and Linux's D-Bus MPRIS (Media Player Remote Interfacing Specification)

Install

Add smtc_windows as a dependency in your pubspec.yaml file.

flutter pub add smtc_windows

Support Development


Usage

class _MyAppState extends State<MyApp> {
  late SMTCWindows smtc;

  @override
  void initState() {
    // initialize SMTC
    smtc = SMTCWindows(
      metadata: const MusicMetadata(
        title: 'Title',
        album: 'Album',
        albumArtist: 'Album Artist',
        artist: 'Artist',
        thumbnail:
            'https://media.glamour.com/photos/5f4c44e20c71c58fc210d35f/master/w_2560%2Cc_limit/mgid_ao_image_mtv.jpg',
      ),
      // Timeline info for the OS media player
      timeline: const PlaybackTimeline(
        startTimeMs: 0,
        endTimeMs: 1000,
        positionMs: 0,
        minSeekTimeMs: 0,
        maxSeekTimeMs: 1000,
      ),
      // Which buttons to show in the OS media player
      config: const SMTCConfig(
        fastForwardEnabled: true,
        nextEnabled: true,
        pauseEnabled: true,
        playEnabled: true,
        rewindEnabled: true,
        prevEnabled: true,
        stopEnabled: true,
      ),
    );
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      try {
        // Listen to button events and update playback status accordingly
        smtc.buttonPressStream.listen((event) {
          switch (event) {
            case PressedButton.play:
              // Update playback status
              smtc.setPlaybackStatus(PlaybackStatus.Playing);
              break;
            case PressedButton.pause:
              smtc.setPlaybackStatus(PlaybackStatus.Paused);
              break;
            case PressedButton.next:
              print('Next');
              break;
            case PressedButton.previous:
              print('Previous');
              break;
            case PressedButton.stop:
              smtc.setPlaybackStatus(PlaybackStatus.Stopped);
              smtc.disableSmtc();
              break;
            default:
              break;
          }
        });
      } catch (e) {
        debugPrint("Error: $e");
      }
    });
    super.initState();
  }

  @override
  void dispose() {
    // Dispose SMTC
    smtc.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Native Packages'),
        ),
        body: ElevatedButton(
          child: const Text("Click"),
          onPressed: () {
            // Update player metadata
            smtc.updateMetadata(
              const MusicMetadata(
                title: 'Title',
                album: 'Album',
                albumArtist: 'Album Artist',
                artist: 'Artist',
                thumbnail:
                    'https://media.glamour.com/photos/5f4c44e20c71c58fc210d35f/master/w_2560%2Cc_limit/mgid_ao_image_mtv.jpg',
              ),
            );
          },
        ),
      ),
    );
  }
}

License

MIT

Author

Kingkor Roy Tirtho

Twitter Follow

GitHub followers

smtc_windows's People

Contributors

krtirtho avatar

Stargazers

 avatar Paul Zarudnev avatar  avatar  avatar  avatar  avatar H3mnz avatar Michael Corrado avatar

Watchers

 avatar  avatar

Forkers

vlado-rudenok

smtc_windows's Issues

How to display a local image?

I am trying to display a locally cached image on SMTC, but it's not working. I've tried removing file:/// and replacing / with \, but neither works. Is this due to Windows security policies preventing access, or is there an issue with the path I've provided?

image

here is the path: file:///C:/Users/xxx/AppData/Local/Temp/sm_caches/assets/5a161a80-286b-1e6d-bbae-d1bc9e4dd67a.png

outdated uuid package

Hi ๐Ÿ‘‹
Could you eventually update the uuid package to ^4.1.0 ?
Best regards

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.