smtc_windows 0.1.0 copy "smtc_windows: ^0.1.0" to clipboard
smtc_windows: ^0.1.0 copied to clipboard

Windows `SystemMediaTransportControls` implementation for Flutter giving access to Windows OS Media Control applet.

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

9
likes
0
pub points
89%
popularity

Publisher

verified publisherkrtirtho.dev

Windows `SystemMediaTransportControls` implementation for Flutter giving access to Windows OS Media Control applet.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

ffi, flutter, flutter_rust_bridge, meta, plugin_platform_interface, uuid

More

Packages that depend on smtc_windows