smtc_windows

Creator: coderz1093

Last updated:

0 purchases

smtc_windows Image
smtc_windows Images

Languages

Categories

Add to Cart

Description:

smtc windows

SMTC_Windows #

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
copied to clipboard
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',
),
);
},
),
),
);
}
}
copied to clipboard
License #
MIT
Author #
Kingkor Roy Tirtho

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.