From 1be1c212f6381e8a630f5ad55ba6230596598272 Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Sun, 27 Sep 2020 13:30:30 +1000 Subject: [PATCH] Update web implementation to use platform interface. --- .../lib/generated_plugin_registrant.dart | 2 +- just_audio/example/pubspec.lock | 7 + just_audio/example/pubspec.yaml | 2 + just_audio/pubspec.yaml | 10 +- just_audio_platform_interface/pubspec.yaml | 2 +- just_audio_web/.gitignore | 44 ++ just_audio_web/.metadata | 10 + just_audio_web/README.md | 5 + just_audio_web/lib/just_audio_web.dart | 454 ++++++------------ just_audio_web/pubspec.lock | 70 +++ just_audio_web/pubspec.yaml | 25 + 11 files changed, 323 insertions(+), 308 deletions(-) create mode 100644 just_audio_web/.gitignore create mode 100644 just_audio_web/.metadata create mode 100644 just_audio_web/README.md create mode 100644 just_audio_web/pubspec.lock create mode 100644 just_audio_web/pubspec.yaml diff --git a/just_audio/example/lib/generated_plugin_registrant.dart b/just_audio/example/lib/generated_plugin_registrant.dart index c23fcae..4b2e81e 100644 --- a/just_audio/example/lib/generated_plugin_registrant.dart +++ b/just_audio/example/lib/generated_plugin_registrant.dart @@ -6,7 +6,7 @@ import 'dart:ui'; import 'package:audio_session/audio_session_web.dart'; -import 'package:just_audio/just_audio_web.dart'; +import 'package:just_audio_web/just_audio_web.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; diff --git a/just_audio/example/pubspec.lock b/just_audio/example/pubspec.lock index 4c844e5..71fdddb 100644 --- a/just_audio/example/pubspec.lock +++ b/just_audio/example/pubspec.lock @@ -121,6 +121,13 @@ packages: relative: true source: path version: "0.0.1" + just_audio_web: + dependency: "direct dev" + description: + path: "../../just_audio_web" + relative: true + source: path + version: "0.0.1" matcher: dependency: transitive description: diff --git a/just_audio/example/pubspec.yaml b/just_audio/example/pubspec.yaml index ef73479..642f2b9 100644 --- a/just_audio/example/pubspec.yaml +++ b/just_audio/example/pubspec.yaml @@ -18,6 +18,8 @@ dev_dependencies: just_audio: path: ../ + just_audio_web: + path: ../../just_audio_web # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/just_audio/pubspec.yaml b/just_audio/pubspec.yaml index ff6bda5..040e760 100644 --- a/just_audio/pubspec.yaml +++ b/just_audio/pubspec.yaml @@ -1,7 +1,7 @@ name: just_audio description: Flutter plugin to play audio from streams, files, assets, DASH/HLS streams and playlists. Works with audio_service to play audio in the background. version: 0.4.5 -homepage: https://github.com/ryanheise/just_audio +homepage: https://github.com/ryanheise/just_audio/tree/master/just_audio environment: sdk: ">=2.7.0 <3.0.0" @@ -35,6 +35,8 @@ flutter: pluginClass: JustAudioPlugin macos: pluginClass: JustAudioPlugin - web: - pluginClass: JustAudioPlugin - fileName: just_audio_web.dart + # web: + # default_package: just_audio_web + # web: + # pluginClass: JustAudioPlugin + # fileName: just_audio_web.dart diff --git a/just_audio_platform_interface/pubspec.yaml b/just_audio_platform_interface/pubspec.yaml index e3f45a2..7781249 100644 --- a/just_audio_platform_interface/pubspec.yaml +++ b/just_audio_platform_interface/pubspec.yaml @@ -1,6 +1,6 @@ name: just_audio_platform_interface description: A common platform interface for the just_audio plugin. -homepage: https://github.com/ryanheise/just_audio/just_audio_platform_interface +homepage: https://github.com/ryanheise/just_audio/tree/master/just_audio_platform_interface # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes version: 0.0.1 diff --git a/just_audio_web/.gitignore b/just_audio_web/.gitignore new file mode 100644 index 0000000..f3c2053 --- /dev/null +++ b/just_audio_web/.gitignore @@ -0,0 +1,44 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Web related +lib/generated_plugin_registrant.dart + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Exceptions to above rules. +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages diff --git a/just_audio_web/.metadata b/just_audio_web/.metadata new file mode 100644 index 0000000..bcef94e --- /dev/null +++ b/just_audio_web/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: bbfbf1770cca2da7c82e887e4e4af910034800b6 + channel: stable + +project_type: app diff --git a/just_audio_web/README.md b/just_audio_web/README.md new file mode 100644 index 0000000..08d4906 --- /dev/null +++ b/just_audio_web/README.md @@ -0,0 +1,5 @@ +# just_audio_web + +The web implementation of [`just_audio`][1]. + +[1]: ../just_audio diff --git a/just_audio_web/lib/just_audio_web.dart b/just_audio_web/lib/just_audio_web.dart index 9932cdd..f11cd2f 100644 --- a/just_audio_web/lib/just_audio_web.dart +++ b/just_audio_web/lib/just_audio_web.dart @@ -5,127 +5,33 @@ import 'dart:math'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; -import 'package:just_audio/just_audio.dart'; +import 'package:just_audio_platform_interface/just_audio_platform_interface.dart'; final Random _random = Random(); -class JustAudioPlugin { +class JustAudioPlugin extends JustAudioPlatform { static void registerWith(Registrar registrar) { - final MethodChannel channel = MethodChannel( - 'com.ryanheise.just_audio.methods', - const StandardMethodCodec(), - registrar.messenger); - final JustAudioPlugin instance = JustAudioPlugin(registrar); - channel.setMethodCallHandler(instance.handleMethodCall); + JustAudioPlatform.instance = JustAudioPlugin(); } - final Registrar registrar; - - JustAudioPlugin(this.registrar); - - Future handleMethodCall(MethodCall call) async { - switch (call.method) { - case 'init': - final String id = call.arguments[0]; - new Html5AudioPlayer(id: id, registrar: registrar); - return null; - case 'setIosCategory': - return null; - default: - throw PlatformException(code: 'Unimplemented'); - } + Future init(InitRequest request) async { + return Html5AudioPlayer(id: request.id); } } -abstract class JustAudioPlayer { +abstract class JustAudioPlayer extends AudioPlayerPlatform { final String id; - final Registrar registrar; - final MethodChannel methodChannel; - final PluginEventChannel eventChannel; - final StreamController eventController = StreamController(); - ProcessingState _processingState = ProcessingState.none; + final eventController = StreamController(); + ProcessingStateMessage _processingState = ProcessingStateMessage.none; bool _playing = false; int _index; - JustAudioPlayer({@required this.id, @required this.registrar}) - : methodChannel = MethodChannel('com.ryanheise.just_audio.methods.$id', - const StandardMethodCodec(), registrar.messenger), - eventChannel = PluginEventChannel('com.ryanheise.just_audio.events.$id', - const StandardMethodCodec(), registrar.messenger) { - methodChannel.setMethodCallHandler(_methodHandler); - eventChannel.controller = eventController; - } - - Future _methodHandler(MethodCall call) async { - try { - final args = call.arguments; - switch (call.method) { - case 'load': - return await load(args[0]); - case 'play': - return await play(); - case 'pause': - return await pause(); - case 'setVolume': - return await setVolume(args[0]); - case 'setSpeed': - return await setSpeed(args[0]); - case 'setLoopMode': - return await setLoopMode(args[0]); - case 'setShuffleModeEnabled': - return await setShuffleModeEnabled(args[0]); - case 'setAutomaticallyWaitsToMinimizeStalling': - return null; - case 'seek': - return await seek(args[0], args[1]); - case 'dispose': - return dispose(); - case 'concatenating.add': - return await concatenatingAdd(args[0], args[1]); - case "concatenating.insert": - return await concatenatingInsert(args[0], args[1], args[2]); - case "concatenating.addAll": - return await concatenatingAddAll(args[0], args[1]); - case "concatenating.insertAll": - return await concatenatingInsertAll(args[0], args[1], args[2]); - case "concatenating.removeAt": - return await concatenatingRemoveAt(args[0], args[1]); - case "concatenating.removeRange": - return await concatenatingRemoveRange(args[0], args[1], args[2]); - case "concatenating.move": - return await concatenatingMove(args[0], args[1], args[2]); - case "concatenating.clear": - return await concatenatingClear(args[0]); - case "setAndroidAudioAttributes": - return null; - default: - throw PlatformException(code: 'Unimplemented'); - } - } catch (e, stacktrace) { - print("$stacktrace"); - rethrow; - } - } - - Future load(Map source); - - Future play(); - - Future pause(); - - Future setVolume(double volume); - - Future setSpeed(double speed); - - Future setLoopMode(int mode); - - Future setShuffleModeEnabled(bool enabled); - - Future seek(int position, int index); + JustAudioPlayer({@required this.id}); @mustCallSuper - void dispose() { + Future dispose(DisposeRequest request) async { eventController.close(); + return DisposeResponse(); } Duration getCurrentPosition(); @@ -134,37 +40,22 @@ abstract class JustAudioPlayer { Duration getDuration(); - concatenatingAdd(String playerId, Map source); - - concatenatingInsert(String playerId, int index, Map source); - - concatenatingAddAll(String playerId, List sources); - - concatenatingInsertAll(String playerId, int index, List sources); - - concatenatingRemoveAt(String playerId, int index); - - concatenatingRemoveRange(String playerId, int start, int end); - - concatenatingMove(String playerId, int currentIndex, int newIndex); - - concatenatingClear(String playerId); - broadcastPlaybackEvent() { - var updateTime = DateTime.now().millisecondsSinceEpoch; - eventController.add({ - 'processingState': _processingState.index, - 'updatePosition': getCurrentPosition()?.inMilliseconds, - 'updateTime': updateTime, - 'bufferedPosition': getBufferedPosition()?.inMilliseconds, + var updateTime = DateTime.now(); + eventController.add(PlaybackEventMessage( + processingState: _processingState, + updatePosition: getCurrentPosition(), + updateTime: updateTime, + bufferedPosition: getBufferedPosition(), // TODO: Icy Metadata - 'icyMetadata': null, - 'duration': getDuration()?.inMilliseconds, - 'currentIndex': _index, - }); + icyMetadata: null, + duration: getDuration(), + currentIndex: _index, + androidAudioSessionId: null, + )); } - transition(ProcessingState processingState) { + transition(ProcessingStateMessage processingState) { _processingState = processingState; broadcastPlaybackEvent(); } @@ -174,12 +65,11 @@ class Html5AudioPlayer extends JustAudioPlayer { AudioElement _audioElement = AudioElement(); Completer _durationCompleter; AudioSourcePlayer _audioSourcePlayer; - LoopMode _loopMode = LoopMode.off; + LoopModeMessage _loopMode = LoopModeMessage.off; bool _shuffleModeEnabled = false; final Map _audioSourcePlayers = {}; - Html5AudioPlayer({@required String id, @required Registrar registrar}) - : super(id: id, registrar: registrar) { + Html5AudioPlayer({@required String id}) : super(id: id) { _audioElement.addEventListener('durationchange', (event) { _durationCompleter?.complete(); broadcastPlaybackEvent(); @@ -194,16 +84,16 @@ class Html5AudioPlayer extends JustAudioPlayer { _currentAudioSourcePlayer.timeUpdated(_audioElement.currentTime); }); _audioElement.addEventListener('loadstart', (event) { - transition(ProcessingState.buffering); + transition(ProcessingStateMessage.buffering); }); _audioElement.addEventListener('waiting', (event) { - transition(ProcessingState.buffering); + transition(ProcessingStateMessage.buffering); }); _audioElement.addEventListener('stalled', (event) { - transition(ProcessingState.buffering); + transition(ProcessingStateMessage.buffering); }); _audioElement.addEventListener('canplaythrough', (event) { - transition(ProcessingState.ready); + transition(ProcessingStateMessage.ready); }); _audioElement.addEventListener('progress', (event) { broadcastPlaybackEvent(); @@ -232,9 +122,9 @@ class Html5AudioPlayer extends JustAudioPlayer { } onEnded() async { - if (_loopMode == LoopMode.one) { - await seek(0, null); - play(); + if (_loopMode == LoopModeMessage.one) { + await _seek(0, null); + _play(); } else { final order = this.order; final orderInv = getInv(order); @@ -244,25 +134,25 @@ class Html5AudioPlayer extends JustAudioPlayer { await _currentAudioSourcePlayer.load(); // Should always be true... if (_playing) { - play(); + _play(); } } else { // reached end of playlist - if (_loopMode == LoopMode.all) { + if (_loopMode == LoopModeMessage.all) { // Loop back to the beginning if (order.length == 1) { - await seek(0, null); - play(); + await _seek(0, null); + _play(); } else { _index = order[0]; await _currentAudioSourcePlayer.load(); // Should always be true... if (_playing) { - play(); + _play(); } } } else { - transition(ProcessingState.completed); + transition(ProcessingStateMessage.completed); } } } @@ -275,18 +165,22 @@ class Html5AudioPlayer extends JustAudioPlayer { : null; @override - Future load(Map source) async { + Stream get playbackEventMessageStream => + eventController.stream; + + @override + Future load(LoadRequest request) async { _currentAudioSourcePlayer?.pause(); - _audioSourcePlayer = getAudioSource(source); + _audioSourcePlayer = getAudioSource(request.audioSourceMessage); _index = 0; if (_shuffleModeEnabled) { _audioSourcePlayer?.shuffle(0, _index); } - return (await _currentAudioSourcePlayer.load())?.inMilliseconds; + return LoadResponse(duration: await _currentAudioSourcePlayer.load()); } Future loadUri(final Uri uri) async { - transition(ProcessingState.loading); + transition(ProcessingStateMessage.loading); final src = uri.toString(); if (src != _audioElement.src) { _durationCompleter = Completer(); @@ -302,7 +196,7 @@ class Html5AudioPlayer extends JustAudioPlayer { _durationCompleter = null; } } - transition(ProcessingState.ready); + transition(ProcessingStateMessage.ready); final seconds = _audioElement.duration; return seconds.isFinite ? Duration(milliseconds: (seconds * 1000).toInt()) @@ -310,42 +204,58 @@ class Html5AudioPlayer extends JustAudioPlayer { } @override - Future play() async { + Future play(PlayRequest request) async { + await _play(); + return PlayResponse(); + } + + Future _play() async { _playing = true; await _currentAudioSourcePlayer.play(); } @override - Future pause() async { + Future pause(PauseRequest request) async { _playing = false; _currentAudioSourcePlayer.pause(); + return PauseResponse(); } @override - Future setVolume(double volume) async { - _audioElement.volume = volume; + Future setVolume(SetVolumeRequest request) async { + _audioElement.volume = request.volume; + return SetVolumeResponse(); } @override - Future setSpeed(double speed) async { - _audioElement.playbackRate = speed; + Future setSpeed(SetSpeedRequest request) async { + _audioElement.playbackRate = request.speed; + return SetSpeedResponse(); } @override - Future setLoopMode(int mode) async { - _loopMode = LoopMode.values[mode]; + Future setLoopMode(SetLoopModeRequest request) async { + _loopMode = request.loopMode; + return SetLoopModeResponse(); } @override - Future setShuffleModeEnabled(bool enabled) async { - _shuffleModeEnabled = enabled; - if (enabled) { + Future setShuffleMode( + SetShuffleModeRequest request) async { + _shuffleModeEnabled = request.shuffleMode == ShuffleModeMessage.all; + if (_shuffleModeEnabled) { _audioSourcePlayer?.shuffle(0, _index); } + return SetShuffleModeResponse(); } @override - Future seek(int position, int newIndex) async { + Future seek(SeekRequest request) async { + await _seek(request.position.inMilliseconds, request.index); + return SeekResponse(); + } + + Future _seek(int position, int newIndex) async { int index = newIndex ?? _index; if (index != _index) { _currentAudioSourcePlayer.pause(); @@ -363,89 +273,70 @@ class Html5AudioPlayer extends JustAudioPlayer { ConcatenatingAudioSourcePlayer _concatenating(String playerId) => _audioSourcePlayers[playerId] as ConcatenatingAudioSourcePlayer; - concatenatingAdd(String playerId, Map source) { - final playlist = _concatenating(playerId); - playlist.add(getAudioSource(source)); - } - - concatenatingInsert(String playerId, int index, Map source) { - _concatenating(playerId).insert(index, getAudioSource(source)); - if (index <= _index) { - _index++; + @override + Future concatenatingInsertAll( + ConcatenatingInsertAllRequest request) async { + _concatenating(request.id) + .insertAll(request.index, getAudioSources(request.children)); + if (request.index <= _index) { + _index += request.children.length; } + return ConcatenatingInsertAllResponse(); } - concatenatingAddAll(String playerId, List sources) { - _concatenating(playerId).addAll(getAudioSources(sources)); - } - - concatenatingInsertAll(String playerId, int index, List sources) { - _concatenating(playerId).insertAll(index, getAudioSources(sources)); - if (index <= _index) { - _index += sources.length; - } - } - - concatenatingRemoveAt(String playerId, int index) async { - // Pause if removing current item - if (_index == index && _playing) { - _currentAudioSourcePlayer.pause(); - } - _concatenating(playerId).removeAt(index); - if (_index == index) { - // Skip backward if there's nothing after this - if (index == _audioSourcePlayer.sequence.length) { - _index--; - } - // Resume playback at the new item (if it exists) - if (_playing && _currentAudioSourcePlayer != null) { - await _currentAudioSourcePlayer.load(); - _currentAudioSourcePlayer.play(); - } - } else if (index < _index) { - // Reflect that the current item has shifted its position - _index--; - } - } - - concatenatingRemoveRange(String playerId, int start, int end) async { - if (_index >= start && _index < end && _playing) { + @override + Future concatenatingRemoveRange( + ConcatenatingRemoveRangeRequest request) async { + if (_index >= request.startIndex && _index < request.endIndex && _playing) { // Pause if removing current item _currentAudioSourcePlayer.pause(); } - _concatenating(playerId).removeRange(start, end); - if (_index >= start && _index < end) { + _concatenating(request.id) + .removeRange(request.startIndex, request.endIndex); + if (_index >= request.startIndex && _index < request.endIndex) { // Skip backward if there's nothing after this - if (start >= _audioSourcePlayer.sequence.length) { - _index = start - 1; + if (request.startIndex >= _audioSourcePlayer.sequence.length) { + _index = request.startIndex - 1; } else { - _index = start; + _index = request.startIndex; } // Resume playback at the new item (if it exists) if (_playing && _currentAudioSourcePlayer != null) { await _currentAudioSourcePlayer.load(); _currentAudioSourcePlayer.play(); } - } else if (end <= _index) { + } else if (request.endIndex <= _index) { // Reflect that the current item has shifted its position - _index -= (end - start); + _index -= (request.endIndex - request.startIndex); } + return ConcatenatingRemoveRangeResponse(); } - concatenatingMove(String playerId, int currentIndex, int newIndex) { - _concatenating(playerId).move(currentIndex, newIndex); - if (currentIndex == _index) { - _index = newIndex; - } else if (currentIndex < _index && newIndex >= _index) { + @override + Future concatenatingMove( + ConcatenatingMoveRequest request) async { + _concatenating(request.id).move(request.currentIndex, request.newIndex); + if (request.currentIndex == _index) { + _index = request.newIndex; + } else if (request.currentIndex < _index && request.newIndex >= _index) { _index--; - } else if (currentIndex > _index && newIndex <= _index) { + } else if (request.currentIndex > _index && request.newIndex <= _index) { _index++; } + return ConcatenatingMoveResponse(); } - concatenatingClear(String playerId) { - _currentAudioSourcePlayer.pause(); - _concatenating(playerId).clear(); + @override + Future setAndroidAudioAttributes( + SetAndroidAudioAttributesRequest request) async { + return SetAndroidAudioAttributesResponse(); + } + + @override + Future + setAutomaticallyWaitsToMinimizeStalling( + SetAutomaticallyWaitsToMinimizeStallingRequest request) async { + return SetAutomaticallyWaitsToMinimizeStallingResponse(); } @override @@ -458,57 +349,56 @@ class Html5AudioPlayer extends JustAudioPlayer { Duration getDuration() => _currentAudioSourcePlayer?.duration; @override - void dispose() { + Future dispose(DisposeRequest request) async { _currentAudioSourcePlayer?.pause(); _audioElement.removeAttribute('src'); _audioElement.load(); - transition(ProcessingState.none); - super.dispose(); + transition(ProcessingStateMessage.none); + return await super.dispose(request); } - List getAudioSources(List json) => - json.map((s) => getAudioSource(s)).toList(); + List getAudioSources(List messages) => + messages.map((message) => getAudioSource(message)).toList(); - AudioSourcePlayer getAudioSource(Map json) { - final String id = json['id']; + AudioSourcePlayer getAudioSource(AudioSourceMessage audioSourceMessage) { + final String id = audioSourceMessage.id; var audioSourcePlayer = _audioSourcePlayers[id]; if (audioSourcePlayer == null) { - audioSourcePlayer = decodeAudioSource(json); + audioSourcePlayer = decodeAudioSource(audioSourceMessage); _audioSourcePlayers[id] = audioSourcePlayer; } return audioSourcePlayer; } - AudioSourcePlayer decodeAudioSource(Map json) { + AudioSourcePlayer decodeAudioSource(AudioSourceMessage audioSourceMessage) { try { - switch (json['type']) { - case 'progressive': - return ProgressiveAudioSourcePlayer( - this, json['id'], Uri.parse(json['uri']), json['headers']); - case "dash": - return DashAudioSourcePlayer( - this, json['id'], Uri.parse(json['uri']), json['headers']); - case "hls": - return HlsAudioSourcePlayer( - this, json['id'], Uri.parse(json['uri']), json['headers']); - case "concatenating": - return ConcatenatingAudioSourcePlayer( - this, - json['id'], - getAudioSources(json['audioSources']), - json['useLazyPreparation']); - case "clipping": - return ClippingAudioSourcePlayer( - this, - json['id'], - getAudioSource(json['audioSource']), - Duration(milliseconds: json['start']), - Duration(milliseconds: json['end'])); - case "looping": - return LoopingAudioSourcePlayer(this, json['id'], - getAudioSource(json['audioSource']), json['count']); - default: - throw Exception("Unknown AudioSource type: " + json['type']); + if (audioSourceMessage is ProgressiveAudioSourceMessage) { + return ProgressiveAudioSourcePlayer(this, audioSourceMessage.id, + Uri.parse(audioSourceMessage.uri), audioSourceMessage.headers); + } else if (audioSourceMessage is DashAudioSourceMessage) { + return DashAudioSourcePlayer(this, audioSourceMessage.id, + Uri.parse(audioSourceMessage.uri), audioSourceMessage.headers); + } else if (audioSourceMessage is HlsAudioSourceMessage) { + return HlsAudioSourcePlayer(this, audioSourceMessage.id, + Uri.parse(audioSourceMessage.uri), audioSourceMessage.headers); + } else if (audioSourceMessage is ConcatenatingAudioSourceMessage) { + return ConcatenatingAudioSourcePlayer( + this, + audioSourceMessage.id, + getAudioSources(audioSourceMessage.children), + audioSourceMessage.useLazyPreparation); + } else if (audioSourceMessage is ClippingAudioSourceMessage) { + return ClippingAudioSourcePlayer( + this, + audioSourceMessage.id, + getAudioSource(audioSourceMessage.child), + audioSourceMessage.start, + audioSourceMessage.end); + } else if (audioSourceMessage is LoopingAudioSourceMessage) { + return LoopingAudioSourcePlayer(this, audioSourceMessage.id, + getAudioSource(audioSourceMessage.child), audioSourceMessage.count); + } else { + throw Exception("Unknown AudioSource type: $audioSourceMessage"); } } catch (e, stacktrace) { print("$stacktrace"); @@ -731,29 +621,6 @@ class ConcatenatingAudioSourcePlayer extends AudioSourcePlayer { return treeIndex; } - add(AudioSourcePlayer player) { - audioSourcePlayers.add(player); - _shuffleOrder.add(audioSourcePlayers.length - 1); - } - - insert(int index, AudioSourcePlayer player) { - audioSourcePlayers.insert(index, player); - for (var i = 0; i < audioSourcePlayers.length; i++) { - if (_shuffleOrder[i] >= index) { - _shuffleOrder[i]++; - } - } - _shuffleOrder.add(index); - } - - addAll(List players) { - audioSourcePlayers.addAll(players); - _shuffleOrder.addAll( - List.generate(players.length, (i) => audioSourcePlayers.length + i) - .toList() - ..shuffle()); - } - insertAll(int index, List players) { audioSourcePlayers.insertAll(index, players); for (var i = 0; i < audioSourcePlayers.length; i++) { @@ -765,18 +632,6 @@ class ConcatenatingAudioSourcePlayer extends AudioSourcePlayer { List.generate(players.length, (i) => index + i).toList()..shuffle()); } - removeAt(int index) { - audioSourcePlayers.removeAt(index); - // 0 1 2 3 - // 3 2 0 1 - for (var i = 0; i < audioSourcePlayers.length; i++) { - if (_shuffleOrder[i] > index) { - _shuffleOrder[i]--; - } - } - _shuffleOrder.removeWhere((i) => i == index); - } - removeRange(int start, int end) { audioSourcePlayers.removeRange(start, end); for (var i = 0; i < audioSourcePlayers.length; i++) { @@ -791,11 +646,6 @@ class ConcatenatingAudioSourcePlayer extends AudioSourcePlayer { audioSourcePlayers.insert( newIndex, audioSourcePlayers.removeAt(currentIndex)); } - - clear() { - audioSourcePlayers.clear(); - _shuffleOrder.clear(); - } } class ClippingAudioSourcePlayer extends IndexedAudioSourcePlayer { diff --git a/just_audio_web/pubspec.lock b/just_audio_web/pubspec.lock new file mode 100644 index 0000000..8325d1d --- /dev/null +++ b/just_audio_web/pubspec.lock @@ -0,0 +1,70 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.14.13" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_web_plugins: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + just_audio_platform_interface: + dependency: "direct main" + description: + path: "../just_audio_platform_interface" + relative: true + source: path + version: "0.0.1" + meta: + dependency: "direct main" + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.8" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.8" +sdks: + dart: ">=2.9.0-14.0.dev <3.0.0" + flutter: ">=1.12.13+hotfix.5" diff --git a/just_audio_web/pubspec.yaml b/just_audio_web/pubspec.yaml new file mode 100644 index 0000000..b4742c0 --- /dev/null +++ b/just_audio_web/pubspec.yaml @@ -0,0 +1,25 @@ +name: just_audio_web +description: Web platform implementation of just_audio +homepage: https://github.com/ryanheise/just_audio/tree/master/just_audio_web +version: 0.0.1 + +flutter: + plugin: + platforms: + web: + pluginClass: JustAudioPlugin + fileName: just_audio_web.dart + +dependencies: + #just_audio_platform_interface: ^0.0.1 + just_audio_platform_interface: + path: ../just_audio_platform_interface + flutter: + sdk: flutter + flutter_web_plugins: + sdk: flutter + meta: ^1.1.8 + +environment: + sdk: ">=2.7.0 <3.0.0" + flutter: ">=1.12.13+hotfix.5"