Add initialPosition and initialIndex parameters to load.
This commit is contained in:
parent
556598a663
commit
f38ff383f5
|
@ -64,6 +64,8 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
|
|||
private Long start;
|
||||
private Long end;
|
||||
private Long seekPos;
|
||||
private long initialPos;
|
||||
private Integer initialIndex;
|
||||
private Result prepareResult;
|
||||
private Result playResult;
|
||||
private Result seekResult;
|
||||
|
@ -185,6 +187,11 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
|
|||
|
||||
@Override
|
||||
public void onTimelineChanged(Timeline timeline, int reason) {
|
||||
if (initialPos != C.TIME_UNSET || initialIndex != null) {
|
||||
player.seekTo(initialIndex, initialPos);
|
||||
initialIndex = null;
|
||||
initialPos = C.TIME_UNSET;
|
||||
}
|
||||
if (reason == Player.TIMELINE_CHANGE_REASON_DYNAMIC) {
|
||||
onItemMayHaveChanged();
|
||||
}
|
||||
|
@ -285,7 +292,11 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
|
|||
try {
|
||||
switch (call.method) {
|
||||
case "load":
|
||||
load(getAudioSource(request.get("audioSource")), result);
|
||||
Long initialPosition = getLong(request.get("initialPosition"));
|
||||
Integer initialIndex = (Integer)request.get("initialIndex");
|
||||
load(getAudioSource(request.get("audioSource")),
|
||||
initialPosition == null ? C.TIME_UNSET : initialPosition / 1000,
|
||||
initialIndex, result);
|
||||
break;
|
||||
case "play":
|
||||
play(result);
|
||||
|
@ -316,7 +327,7 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
|
|||
case "seek":
|
||||
Long position = getLong(request.get("position"));
|
||||
Integer index = (Integer)request.get("index");
|
||||
seek(position == null ? C.TIME_UNSET : position / 1000, result, index);
|
||||
seek(position == null ? C.TIME_UNSET : position / 1000, index, result);
|
||||
break;
|
||||
case "concatenatingInsertAll":
|
||||
concatenating(request.get("id"))
|
||||
|
@ -492,7 +503,9 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
|
|||
return new DefaultDataSourceFactory(context, httpDataSourceFactory);
|
||||
}
|
||||
|
||||
private void load(final MediaSource mediaSource, final Result result) {
|
||||
private void load(final MediaSource mediaSource, final long initialPosition, final Integer initialIndex, final Result result) {
|
||||
this.initialPos = initialPosition;
|
||||
this.initialIndex = initialIndex;
|
||||
switch (processingState) {
|
||||
case none:
|
||||
break;
|
||||
|
@ -662,7 +675,7 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Aud
|
|||
player.setShuffleModeEnabled(enabled);
|
||||
}
|
||||
|
||||
public void seek(final long position, final Result result, final Integer index) {
|
||||
public void seek(final long position, final Integer index, final Result result) {
|
||||
if (processingState == ProcessingState.none || processingState == ProcessingState.loading) {
|
||||
result.success(new HashMap<String, Object>());
|
||||
return;
|
||||
|
|
|
@ -120,16 +120,16 @@ packages:
|
|||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.5.4"
|
||||
version: "0.5.4+1"
|
||||
just_audio_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: just_audio_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
path: "../../just_audio_platform_interface"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.1.0"
|
||||
just_audio_web:
|
||||
dependency: "direct main"
|
||||
dependency: transitive
|
||||
description:
|
||||
path: "../../just_audio_web"
|
||||
relative: true
|
||||
|
|
|
@ -442,20 +442,25 @@ class AudioPlayer {
|
|||
Future<Duration> setAsset(String assetPath) =>
|
||||
load(AudioSource.uri(Uri.parse('asset:///$assetPath')));
|
||||
|
||||
/// Loads audio from an [AudioSource] and completes when the audio is ready
|
||||
/// to play with the duration of that audio, or null if the duration is unknown.
|
||||
/// Loads audio from an [AudioSource] and completes when the audio is ready to
|
||||
/// play with the duration of that audio, or null if the duration is unknown.
|
||||
/// Optionally specify [initialPosition] and [initialIndex] to seek to an
|
||||
/// initial position within a particular item (defaulting to position zero of
|
||||
/// the first item).
|
||||
///
|
||||
/// This method throws:
|
||||
///
|
||||
/// * [PlayerException] if the audio source was unable to be loaded.
|
||||
/// * [PlayerInterruptedException] if another call to [load] happened before
|
||||
/// this call completed.
|
||||
Future<Duration> load(AudioSource source) async {
|
||||
Future<Duration> load(AudioSource source,
|
||||
{Duration initialPosition, int initialIndex}) async {
|
||||
if (_disposed) return null;
|
||||
try {
|
||||
_audioSource = source;
|
||||
_broadcastSequence();
|
||||
final duration = await _load(source);
|
||||
final duration = await _load(source,
|
||||
initialPosition: initialPosition, initialIndex: initialIndex);
|
||||
// Wait for loading state to pass.
|
||||
await processingStateStream
|
||||
.firstWhere((state) => state != ProcessingState.loading);
|
||||
|
@ -474,7 +479,8 @@ class AudioPlayer {
|
|||
_audioSources[source._id] = source;
|
||||
}
|
||||
|
||||
Future<Duration> _load(AudioSource source) async {
|
||||
Future<Duration> _load(AudioSource source,
|
||||
{Duration initialPosition, int initialIndex}) async {
|
||||
try {
|
||||
if (!kIsWeb && source._requiresHeaders) {
|
||||
if (_proxy == null) {
|
||||
|
@ -484,7 +490,11 @@ class AudioPlayer {
|
|||
}
|
||||
await source._setup(this);
|
||||
_durationFuture = (await _platform)
|
||||
.load(LoadRequest(audioSourceMessage: source._toMessage()))
|
||||
.load(LoadRequest(
|
||||
audioSourceMessage: source._toMessage(),
|
||||
initialPosition: initialPosition,
|
||||
initialIndex: initialIndex,
|
||||
))
|
||||
.then((response) => response.duration);
|
||||
final duration = await _durationFuture;
|
||||
_durationSubject.add(duration);
|
||||
|
|
|
@ -110,10 +110,17 @@ packages:
|
|||
just_audio_platform_interface:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: just_audio_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
path: "../just_audio_platform_interface"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.1.0"
|
||||
just_audio_web:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../just_audio_web"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.1.0"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -8,8 +8,12 @@ environment:
|
|||
flutter: ">=1.12.13+hotfix.5"
|
||||
|
||||
dependencies:
|
||||
just_audio_platform_interface: ^1.1.0
|
||||
just_audio_web: ^0.1.0
|
||||
# just_audio_platform_interface: ^1.2.0
|
||||
# just_audio_web: ^0.1.0
|
||||
just_audio_platform_interface:
|
||||
path: ../just_audio_platform_interface
|
||||
just_audio_web:
|
||||
path: ../just_audio_web
|
||||
audio_session: ^0.0.9
|
||||
rxdart: ^0.24.1
|
||||
path: ^1.6.4
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
## 1.2.0
|
||||
|
||||
- Add initialPosition and initialIndex to LoadRequest.
|
||||
|
||||
## 1.1.0
|
||||
|
||||
- Player is now disposed via JustAudioPlatform.disposePlayer().
|
||||
|
|
|
@ -297,11 +297,19 @@ class DisposePlayerResponse {
|
|||
/// audio source.
|
||||
class LoadRequest {
|
||||
final AudioSourceMessage audioSourceMessage;
|
||||
final Duration initialPosition;
|
||||
final int initialIndex;
|
||||
|
||||
LoadRequest({@required this.audioSourceMessage});
|
||||
LoadRequest({
|
||||
@required this.audioSourceMessage,
|
||||
this.initialPosition,
|
||||
this.initialIndex,
|
||||
});
|
||||
|
||||
Map<dynamic, dynamic> toMap() => {
|
||||
'audioSource': audioSourceMessage.toMap(),
|
||||
'initialPosition': initialPosition?.inMicroseconds,
|
||||
'initialIndex': initialIndex,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ description: A common platform interface for the just_audio plugin.
|
|||
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: 1.1.0
|
||||
version: 1.2.0
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
|
|
|
@ -11,7 +11,9 @@ flutter:
|
|||
fileName: just_audio_web.dart
|
||||
|
||||
dependencies:
|
||||
just_audio_platform_interface: ^1.1.0
|
||||
# just_audio_platform_interface: ^1.2.0
|
||||
just_audio_platform_interface:
|
||||
path: ../just_audio_platform_interface
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_web_plugins:
|
||||
|
|
Loading…
Reference in New Issue