MusicPlayer/lib/ui/player_web_interface.dart

34 lines
963 B
Dart

// ignore_for_file: avoid_web_libraries_in_flutter
import 'dart:html';
import 'package:audio_service_web/js/media_session_web.dart';
import 'package:music_web_player/api.dart';
void updateMusicSession({
required MusicEntry entry,
required Function() onPlay,
required Function() onPause,
required Function() onStop,
required Function() onPreviousTrack,
required Function() onNextTrack,
}) {
MediaSession.metadata = MediaMetadata({
"title": entry.title,
"artist": entry.artist,
"artwork": [
{
"src": entry.coverURL,
"sizes": "512x512",
"type": "image/jpeg",
}
]
});
MediaSession.setActionHandler("play", (p0) => onPlay());
MediaSession.setActionHandler("pause", (p0) => onPause());
MediaSession.setActionHandler("stop", (p0) => onStop());
MediaSession.setActionHandler("previoustrack", (p0) => onPreviousTrack());
MediaSession.setActionHandler("nexttrack", (p0) => onNextTrack());
}