From b1f34f0c36f6ac06e09f1d2918e2108964064dea Mon Sep 17 00:00:00 2001 From: Abdellatif Bakka Date: Sun, 24 Sep 2023 18:41:22 +0100 Subject: [PATCH 1/7] update --- just_audio/lib/just_audio.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/just_audio/lib/just_audio.dart b/just_audio/lib/just_audio.dart index 60cb5e67b..cd210f951 100644 --- a/just_audio/lib/just_audio.dart +++ b/just_audio/lib/just_audio.dart @@ -864,7 +864,7 @@ class AudioPlayer { /// original [AudioSource]. If [end] is null, it will be reset to the end of /// the original [AudioSource]. This method cannot be called from the /// [ProcessingState.idle] state. - Future setClip({Duration? start, Duration? end}) async { + Future setClip({Duration? start, Duration? end, dynamic tag: tag}) async { if (_disposed) return null; _setPlatformActive(true)?.catchError((dynamic e) async => null); final duration = await _load( @@ -875,6 +875,7 @@ class AudioPlayer { child: _audioSource as UriAudioSource, start: start, end: end, + tag: tag )); return duration; } From 95457ac656c6d4153cb69865220200048ce2d840 Mon Sep 17 00:00:00 2001 From: Abdellatif Bakka Date: Sun, 24 Sep 2023 19:03:31 +0100 Subject: [PATCH 2/7] update --- just_audio/lib/just_audio.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/just_audio/lib/just_audio.dart b/just_audio/lib/just_audio.dart index cd210f951..89112c3be 100644 --- a/just_audio/lib/just_audio.dart +++ b/just_audio/lib/just_audio.dart @@ -864,7 +864,7 @@ class AudioPlayer { /// original [AudioSource]. If [end] is null, it will be reset to the end of /// the original [AudioSource]. This method cannot be called from the /// [ProcessingState.idle] state. - Future setClip({Duration? start, Duration? end, dynamic tag: tag}) async { + Future setClip({Duration? start, Duration? end, dynamic tag}) async { if (_disposed) return null; _setPlatformActive(true)?.catchError((dynamic e) async => null); final duration = await _load( From 5880ff42465be76e7504a06cf13e638c744af688 Mon Sep 17 00:00:00 2001 From: Mathis Fqs Date: Tue, 2 Apr 2024 14:35:23 +0200 Subject: [PATCH 3/7] Changes on just_audio and the background package. Adding tags on convenience functions, updating doc, and putting an assert with correct debug message before the cast. --- just_audio/lib/just_audio.dart | 30 +++++++++++++------ .../lib/just_audio_background.dart | 9 +++++- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/just_audio/lib/just_audio.dart b/just_audio/lib/just_audio.dart index 759835e82..161a93a47 100644 --- a/just_audio/lib/just_audio.dart +++ b/just_audio/lib/just_audio.dart @@ -673,7 +673,7 @@ class AudioPlayer { /// This is equivalent to: /// /// ``` - /// setAudioSource(AudioSource.uri(Uri.parse(url), headers: headers), + /// setAudioSource(AudioSource.uri(Uri.parse(url), headers: headers, tag: tag), /// initialPosition: Duration.zero, preload: true); /// ``` /// @@ -683,9 +683,12 @@ class AudioPlayer { Map? headers, Duration? initialPosition, bool preload = true, + dynamic tag, }) => - setAudioSource(AudioSource.uri(Uri.parse(url), headers: headers), - initialPosition: initialPosition, preload: preload); + setAudioSource( + AudioSource.uri(Uri.parse(url), headers: headers, tag: tag), + initialPosition: initialPosition, + preload: preload); /// Convenience method to set the audio source to a file, preloaded by /// default, with an initial position of zero by default. @@ -693,7 +696,7 @@ class AudioPlayer { /// This is equivalent to: /// /// ``` - /// setAudioSource(AudioSource.uri(Uri.file(filePath)), + /// setAudioSource(AudioSource.uri(Uri.file(filePath), tag: tag), /// initialPosition: Duration.zero, preload: true); /// ``` /// @@ -702,8 +705,9 @@ class AudioPlayer { String filePath, { Duration? initialPosition, bool preload = true, + dynamic tag, }) => - setAudioSource(AudioSource.file(filePath), + setAudioSource(AudioSource.file(filePath, tag: tag), initialPosition: initialPosition, preload: preload); /// Convenience method to set the audio source to an asset, preloaded by @@ -712,7 +716,7 @@ class AudioPlayer { /// For assets within the same package, this is equivalent to: /// /// ``` - /// setAudioSource(AudioSource.uri(Uri.parse('asset:///$assetPath')), + /// setAudioSource(AudioSource.uri(Uri.parse('asset:///$assetPath'), tag: tag), /// initialPosition: Duration.zero, preload: true); /// ``` /// @@ -725,9 +729,10 @@ class AudioPlayer { String? package, bool preload = true, Duration? initialPosition, + dynamic tag, }) => setAudioSource( - AudioSource.asset(assetPath, package: package), + AudioSource.asset(assetPath, package: package, tag: tag), initialPosition: initialPosition, preload: preload, ); @@ -753,6 +758,8 @@ class AudioPlayer { /// * [PlayerInterruptedException] if another audio source was loaded before /// this call completed or the player was stopped or disposed of before the /// call completed. + /// + /// See [AudioSource] for a detailed explanation of the AudioSource object. Future setAudioSource( AudioSource source, { bool preload = true, @@ -2169,6 +2176,11 @@ abstract class AudioSource { /// automatically detect the stream type. On Android, the type of stream will /// be guessed from the extension. /// + /// The tag is for associating your app's own data with each audio source. + /// When using just_audio_background,because then it has to be a MediaItem, + /// a class provided by this package. If you want to manage this tag object by yourself, + /// consider using the plugin audio_service instead. + /// /// If you are loading DASH or HLS streams that do not have standard "mpd" or /// "m3u8" extensions in their URIs, this method will fail to detect the /// stream type on Android. If you know in advance what type of audio stream @@ -2196,7 +2208,7 @@ abstract class AudioSource { /// This is equivalent to: /// /// ``` - /// AudioSource.uri(Uri.file(filePath)); + /// AudioSource.uri(Uri.file(filePath), tag: tag); /// ``` static UriAudioSource file(String filePath, {dynamic tag}) { return AudioSource.uri(Uri.file(filePath), tag: tag); @@ -2207,7 +2219,7 @@ abstract class AudioSource { /// For assets within the same package, this is equivalent to: /// /// ``` - /// AudioSource.uri(Uri.parse('asset:///$assetPath')); + /// AudioSource.uri(Uri.parse('asset:///$assetPath'), tag: tag); /// ``` /// /// If the asset is to be loaded from a different package, the [package] diff --git a/just_audio_background/lib/just_audio_background.dart b/just_audio_background/lib/just_audio_background.dart index 17caf5897..b60451605 100644 --- a/just_audio_background/lib/just_audio_background.dart +++ b/just_audio_background/lib/just_audio_background.dart @@ -582,7 +582,14 @@ class _PlayerAudioHandler extends BaseAudioHandler await (await _player).setPreferredPeakBitRate(request); void _updateQueue() { - queue.add(sequence.map((source) => source.tag as MediaItem).toList()); + queue.add(sequence.map((source) { + assert( + source.tag is MediaItem, + '''Error : When using just_audio_background, you should always use a MediaItem as tag when setting an AudioSource. See AudioSource.uri documentation for more information.''', + ); + + return (source.tag as MediaItem); + }).toList()); } void _updateShuffleIndices() { From 3c6186dd33ff8c05ec3e276171b04a187ed87b9e Mon Sep 17 00:00:00 2001 From: Mathis Fouques <43168403+mathisfouques@users.noreply.github.com> Date: Thu, 4 Apr 2024 16:37:05 +0200 Subject: [PATCH 4/7] Fix small typo error --- just_audio/lib/just_audio.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/just_audio/lib/just_audio.dart b/just_audio/lib/just_audio.dart index 161a93a47..c52c62f2c 100644 --- a/just_audio/lib/just_audio.dart +++ b/just_audio/lib/just_audio.dart @@ -2177,7 +2177,7 @@ abstract class AudioSource { /// be guessed from the extension. /// /// The tag is for associating your app's own data with each audio source. - /// When using just_audio_background,because then it has to be a MediaItem, + /// When using just_audio_background, it has to be a MediaItem, /// a class provided by this package. If you want to manage this tag object by yourself, /// consider using the plugin audio_service instead. /// From 79f48737a2ea61aa7347f81b9b901ca336e6bf79 Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Mon, 27 May 2024 00:47:44 +1000 Subject: [PATCH 5/7] Polish comments/assertions. --- just_audio/lib/just_audio.dart | 16 +++++++++------- .../lib/just_audio_background.dart | 11 +++-------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/just_audio/lib/just_audio.dart b/just_audio/lib/just_audio.dart index 1f7a0e4e7..c8ec8043c 100644 --- a/just_audio/lib/just_audio.dart +++ b/just_audio/lib/just_audio.dart @@ -759,8 +759,6 @@ class AudioPlayer { /// * [PlayerInterruptedException] if another audio source was loaded before /// this call completed or the player was stopped or disposed of before the /// call completed. - /// - /// See [AudioSource] for a detailed explanation of the AudioSource object. Future setAudioSource( AudioSource source, { bool preload = true, @@ -2205,11 +2203,6 @@ abstract class AudioSource { /// automatically detect the stream type. On Android, the type of stream will /// be guessed from the extension. /// - /// The tag is for associating your app's own data with each audio source. - /// When using just_audio_background, it has to be a MediaItem, - /// a class provided by this package. If you want to manage this tag object by yourself, - /// consider using the plugin audio_service instead. - /// /// If you are loading DASH or HLS streams that do not have standard "mpd" or /// "m3u8" extensions in their URIs, this method will fail to detect the /// stream type on Android. If you know in advance what type of audio stream @@ -2218,6 +2211,15 @@ abstract class AudioSource { /// /// If headers are set, just_audio will create a cleartext local HTTP proxy on /// your device to forward HTTP requests with headers included. + /// + /// The [tag] is for associating your app's own data with each audio source, + /// e.g. title, cover art, a primary key for your DB. Such data can be + /// conveniently retrieved from the tag while rendering the UI. + /// + /// When using just_audio_background, [tag] must be a MediaItem, a class + /// provided by that package. If you wish to have more control over the tag + /// for background audio purposes, consider using the plugin audio_service + /// instead of just_audio_background. static UriAudioSource uri(Uri uri, {Map? headers, dynamic tag}) { bool hasExtension(Uri uri, String extension) => diff --git a/just_audio_background/lib/just_audio_background.dart b/just_audio_background/lib/just_audio_background.dart index 0fd012264..028c7ac07 100644 --- a/just_audio_background/lib/just_audio_background.dart +++ b/just_audio_background/lib/just_audio_background.dart @@ -594,14 +594,9 @@ class _PlayerAudioHandler extends BaseAudioHandler await (await _player).setPreferredPeakBitRate(request); void _updateQueue() { - queue.add(sequence.map((source) { - assert( - source.tag is MediaItem, - '''Error : When using just_audio_background, you should always use a MediaItem as tag when setting an AudioSource. See AudioSource.uri documentation for more information.''', - ); - - return (source.tag as MediaItem); - }).toList()); + assert(sequence.every((source) => source.tag is MediaItem), + 'Error : When using just_audio_background, you should always use a MediaItem as tag when setting an AudioSource. See AudioSource.uri documentation for more information.'); + queue.add(sequence.map((source) => source.tag as MediaItem).toList()); } void _updateShuffleIndices() { From 540dd29aed6b4454ccf545cb963572803978c999 Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Mon, 27 May 2024 01:40:10 +1000 Subject: [PATCH 6/7] Add comma. --- just_audio/lib/just_audio.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/just_audio/lib/just_audio.dart b/just_audio/lib/just_audio.dart index 83eb3bc75..591fcf781 100644 --- a/just_audio/lib/just_audio.dart +++ b/just_audio/lib/just_audio.dart @@ -889,7 +889,8 @@ class AudioPlayer { /// original [AudioSource]. If [end] is null, it will be reset to the end of /// the original [AudioSource]. This method cannot be called from the /// [ProcessingState.idle] state. - Future setClip({Duration? start, Duration? end, dynamic tag}) async { + Future setClip( + {Duration? start, Duration? end, dynamic tag}) async { if (_disposed) return null; _setPlatformActive(true)?.catchError((dynamic e) async => null); final duration = await _load( @@ -900,7 +901,7 @@ class AudioPlayer { child: _audioSource as UriAudioSource, start: start, end: end, - tag: tag + tag: tag, )); return duration; } From 33a71e3602b2aa5c3df0c3a483e846427568dcd2 Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Mon, 27 May 2024 01:44:22 +1000 Subject: [PATCH 7/7] Update changelog. --- just_audio/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/just_audio/CHANGELOG.md b/just_audio/CHANGELOG.md index d591eab4c..14873f1a5 100644 --- a/just_audio/CHANGELOG.md +++ b/just_audio/CHANGELOG.md @@ -1,6 +1,8 @@ ## 0.9.39 * Apply preferPreciseDurationAndTiming to files (@canxin121). +* Add tag parameter to setUrl/setFilePath/setAsset (@mathisfouques). +* Add tag parameter to setClip (@goviral-ma). ## 0.9.38