Skip to content

Commit

Permalink
Formatting and nullability.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Jan 26, 2025
1 parent e8c4c42 commit 2a9ca4e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 48 deletions.
4 changes: 2 additions & 2 deletions audio_service/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
23 changes: 12 additions & 11 deletions audio_service_web/lib/audio_service_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -112,7 +112,7 @@ class AudioServiceWeb extends AudioServicePlatform {
);
break;
default:
// no-op
// no-op
break;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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,
),
);
Expand Down
67 changes: 33 additions & 34 deletions audio_service_web/lib/js/media_session_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
library media_session_web;

import 'dart:js_interop';
import 'package:web/web.dart' as web;

/// Media session playback state types.
///
Expand Down Expand Up @@ -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,
});
}
2 changes: 1 addition & 1 deletion audio_service_web/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 2a9ca4e

Please sign in to comment.