diff --git a/audio_service/pubspec.yaml b/audio_service/pubspec.yaml index 86207f6d..5b85179e 100644 --- a/audio_service/pubspec.yaml +++ b/audio_service/pubspec.yaml @@ -31,8 +31,8 @@ dependencies: # path: audio_service_web # Use these deps when publishing. - audio_service_platform_interface: ^0.1.2 - audio_service_web: ^0.1.3 + audio_service_platform_interface: ^0.1.3 + audio_service_web: ^0.1.4 audio_session: ^0.1.20 rxdart: '>=0.26.0 <0.29.0' diff --git a/audio_service_web/lib/audio_service_web.dart b/audio_service_web/lib/audio_service_web.dart index 82d562eb..059aa1f7 100644 --- a/audio_service_web/lib/audio_service_web.dart +++ b/audio_service_web/lib/audio_service_web.dart @@ -17,11 +17,11 @@ class AudioServiceWeb extends AudioServicePlatform { web.MediaSession get _mediaSession => web.window.navigator.mediaSession; final _mediaSessionSupported = _SupportChecker( - () => js.globalContext.hasProperty('MediaSession'.toJS).toDart, + () => js.globalContext.hasProperty('MediaSession'.toJS).toDart, "MediaSession is not supported in this browser, so plugin is no-op", ); final _setPositionStateSupported = _SupportChecker( - () => web.window.navigator.mediaSession + () => web.window.navigator.mediaSession .hasProperty('setPositionState'.toJS) .toDart, "MediaSession.setPositionState is not supported in this browser", @@ -112,7 +112,7 @@ class AudioServiceWeb extends AudioServicePlatform { ); break; default: - // no-op + // no-op break; } } @@ -125,13 +125,13 @@ class AudioServiceWeb extends AudioServicePlatform { ((MediaSessionActionDetails details) { // Browsers use seconds handlerCallbacks?.seek(SeekRequest( - position: - Duration(milliseconds: (details.seekTime * 1000).round()), + position: Duration( + milliseconds: (details.seekTime! * 1000).round()), )); }).toJS); break; default: - // no-op + // no-op break; } } @@ -164,17 +164,18 @@ class AudioServiceWeb extends AudioServicePlatform { return; } mediaItem = request.mediaItem; - final artist = mediaItem!.artist; - final album = mediaItem!.album; + final artist = mediaItem!.artist ?? ''; + final album = mediaItem!.album ?? ''; final artUri = mediaItem!.artUri; _mediaSession.metadata = web.MediaMetadata( web.MediaMetadataInit( title: mediaItem!.title, - artist: artist.toString(), - album: album.toString(), + artist: artist, + album: album, artwork: [ - web.MediaImage(src: artUri.toString(), sizes: '512x512'), + if (artUri != null) + web.MediaImage(src: artUri.toString(), sizes: '512x512'), ].toJS, ), ); diff --git a/audio_service_web/lib/js/media_session_web.dart b/audio_service_web/lib/js/media_session_web.dart index 91470e15..9a5846c6 100644 --- a/audio_service_web/lib/js/media_session_web.dart +++ b/audio_service_web/lib/js/media_session_web.dart @@ -7,7 +7,6 @@ library media_session_web; import 'dart:js_interop'; -import 'package:web/web.dart' as web; /// Media session playback state types. /// @@ -54,41 +53,41 @@ typedef MediaSessionActionHandler = dynamic Function(MediaSessionActionDetails); @JS() @anonymous extension type MediaSessionActionDetails._(JSObject _) implements JSObject { -/// An action type string taken from the [MediaActions], indicating which -/// type of action needs to be performed. -external String get action; + /// An action type string taken from the [MediaActions], indicating which + /// type of action needs to be performed. + external String get action; -/// Indicates whether or not to perform a "fast" seek. -/// -/// A `seekto` action may optionally include this property. -/// -/// A "fast" seek is a seek being performed in a rapid sequence, such as when -/// fast-forwarding or reversing through the media, rapidly skipping through it. -/// -/// This property can be used to indicate that you should use the shortest possible -/// method to seek the media. This property is not included on the final action in -/// the seek sequence in this situation. -external bool get fastSeek; + /// Indicates whether or not to perform a "fast" seek. + /// + /// A `seekto` action may optionally include this property. + /// + /// A "fast" seek is a seek being performed in a rapid sequence, such as when + /// fast-forwarding or reversing through the media, rapidly skipping through it. + /// + /// This property can be used to indicate that you should use the shortest possible + /// method to seek the media. This property is not included on the final action in + /// the seek sequence in this situation. + external bool? get fastSeek; -/// If the action is either `seekforward` or `seekbackward` -/// and this property is present, it is a floating point value which indicates -/// the seek interval. -/// -/// If this property isn't present, those actions should choose a reasonable -/// default interval. -external double get seekOffset; + /// If the action is either `seekforward` or `seekbackward` + /// and this property is present, it is a floating point value which indicates + /// the seek interval. + /// + /// If this property isn't present, those actions should choose a reasonable + /// default interval. + external double? get seekOffset; -/// If the action is `seekto`, this property is present and -/// indicates the absolute time within the media to move the playback position to. -/// -/// This property is not present for other action types. -external double get seekTime; + /// If the action is `seekto`, this property is present and + /// indicates the absolute time within the media to move the playback position to. + /// + /// This property is not present for other action types. + external double? get seekTime; -/// Creates the details. -external factory MediaSessionActionDetails({ -String? action, -bool? fastSeek, -double? seekOffset, -double? seekTime, -}); + /// Creates the details. + external factory MediaSessionActionDetails({ + String? action, + bool? fastSeek, + double? seekOffset, + double? seekTime, + }); } diff --git a/audio_service_web/pubspec.yaml b/audio_service_web/pubspec.yaml index 697499d7..2bf581e9 100644 --- a/audio_service_web/pubspec.yaml +++ b/audio_service_web/pubspec.yaml @@ -1,6 +1,6 @@ name: audio_service_web description: Web platform implementation of audio_service. This implementation is endorsed and therefore doesn't require a direct dependency. -version: 0.1.3 +version: 0.1.4 homepage: https://github.com/ryanheise/audio_service/tree/master/audio_service_web environment: