Rename audioSources/audioSource to children/child.
This commit is contained in:
parent
e032b8137f
commit
f9a77b16e3
|
@ -55,7 +55,7 @@ Gapless playlists:
|
||||||
```dart
|
```dart
|
||||||
await player.load(
|
await player.load(
|
||||||
ConcatenatingAudioSource(
|
ConcatenatingAudioSource(
|
||||||
audioSources: [
|
children: [
|
||||||
AudioSource.uri(Uri.parse("https://example.com/track1.mp3")),
|
AudioSource.uri(Uri.parse("https://example.com/track1.mp3")),
|
||||||
AudioSource.uri(Uri.parse("https://example.com/track2.mp3")),
|
AudioSource.uri(Uri.parse("https://example.com/track2.mp3")),
|
||||||
AudioSource.uri(Uri.parse("https://example.com/track3.mp3")),
|
AudioSource.uri(Uri.parse("https://example.com/track3.mp3")),
|
||||||
|
@ -83,8 +83,8 @@ player.load(
|
||||||
LoopingAudioSource(
|
LoopingAudioSource(
|
||||||
count: 4,
|
count: 4,
|
||||||
// Play children one after the other
|
// Play children one after the other
|
||||||
audioSource: ConcatenatingAudioSource(
|
child: ConcatenatingAudioSource(
|
||||||
audioSources: [
|
children: [
|
||||||
// Play a regular media file
|
// Play a regular media file
|
||||||
ProgressiveAudioSource(Uri.parse("https://example.com/foo.mp3")),
|
ProgressiveAudioSource(Uri.parse("https://example.com/foo.mp3")),
|
||||||
// Play a DASH stream
|
// Play a DASH stream
|
||||||
|
@ -93,7 +93,7 @@ player.load(
|
||||||
HlsAudioSource(Uri.parse("https://example.com/audio.m3u8")),
|
HlsAudioSource(Uri.parse("https://example.com/audio.m3u8")),
|
||||||
// Play a segment of the child
|
// Play a segment of the child
|
||||||
ClippingAudioSource(
|
ClippingAudioSource(
|
||||||
audioSource: ProgressiveAudioSource(Uri.parse("https://w.xyz/p.mp3")),
|
child: ProgressiveAudioSource(Uri.parse("https://w.xyz/p.mp3")),
|
||||||
start: Duration(seconds: 25),
|
start: Duration(seconds: 25),
|
||||||
end: Duration(seconds: 30),
|
end: Duration(seconds: 30),
|
||||||
),
|
),
|
||||||
|
|
|
@ -15,13 +15,13 @@ class _MyAppState extends State<MyApp> {
|
||||||
final _volumeSubject = BehaviorSubject.seeded(1.0);
|
final _volumeSubject = BehaviorSubject.seeded(1.0);
|
||||||
final _speedSubject = BehaviorSubject.seeded(1.0);
|
final _speedSubject = BehaviorSubject.seeded(1.0);
|
||||||
AudioPlayer _player;
|
AudioPlayer _player;
|
||||||
ConcatenatingAudioSource _playlist = ConcatenatingAudioSource(audioSources: [
|
ConcatenatingAudioSource _playlist = ConcatenatingAudioSource(children: [
|
||||||
LoopingAudioSource(
|
LoopingAudioSource(
|
||||||
count: 2,
|
count: 2,
|
||||||
audioSource: ClippingAudioSource(
|
child: ClippingAudioSource(
|
||||||
start: Duration(seconds: 60),
|
start: Duration(seconds: 60),
|
||||||
end: Duration(seconds: 65),
|
end: Duration(seconds: 65),
|
||||||
audioSource: AudioSource.uri(Uri.parse(
|
child: AudioSource.uri(Uri.parse(
|
||||||
"https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3")),
|
"https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3")),
|
||||||
tag: AudioMetadata(
|
tag: AudioMetadata(
|
||||||
album: "Science Friday",
|
album: "Science Friday",
|
||||||
|
@ -31,7 +31,7 @@ class _MyAppState extends State<MyApp> {
|
||||||
),
|
),
|
||||||
//LoopingAudioSource(
|
//LoopingAudioSource(
|
||||||
// count: 2,
|
// count: 2,
|
||||||
// audioSource: AudioSource.uri(
|
// child: AudioSource.uri(
|
||||||
// Uri.parse(
|
// Uri.parse(
|
||||||
// "https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3"),
|
// "https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3"),
|
||||||
// tag: AudioMetadata(
|
// tag: AudioMetadata(
|
||||||
|
@ -43,7 +43,7 @@ class _MyAppState extends State<MyApp> {
|
||||||
//ClippingAudioSource(
|
//ClippingAudioSource(
|
||||||
// start: Duration(seconds: 60),
|
// start: Duration(seconds: 60),
|
||||||
// end: Duration(seconds: 65),
|
// end: Duration(seconds: 65),
|
||||||
// audioSource: AudioSource.uri(Uri.parse(
|
// child: AudioSource.uri(Uri.parse(
|
||||||
// "https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3")),
|
// "https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3")),
|
||||||
// tag: AudioMetadata(
|
// tag: AudioMetadata(
|
||||||
// album: "Science Friday",
|
// album: "Science Friday",
|
||||||
|
|
|
@ -353,7 +353,7 @@ class AudioPlayer {
|
||||||
final duration = await _load(start == null && end == null
|
final duration = await _load(start == null && end == null
|
||||||
? _audioSource
|
? _audioSource
|
||||||
: ClippingAudioSource(
|
: ClippingAudioSource(
|
||||||
audioSource: _audioSource,
|
child: _audioSource,
|
||||||
start: start,
|
start: start,
|
||||||
end: end,
|
end: end,
|
||||||
));
|
));
|
||||||
|
@ -880,12 +880,12 @@ abstract class AudioSource {
|
||||||
return HlsAudioSource(Uri.parse(json['uri']), headers: json['headers']);
|
return HlsAudioSource(Uri.parse(json['uri']), headers: json['headers']);
|
||||||
case "concatenating":
|
case "concatenating":
|
||||||
return ConcatenatingAudioSource(
|
return ConcatenatingAudioSource(
|
||||||
audioSources: (json['audioSources'] as List)
|
children: (json['audioSources'] as List)
|
||||||
.map((s) => AudioSource.fromJson(s))
|
.map((s) => AudioSource.fromJson(s))
|
||||||
.toList());
|
.toList());
|
||||||
case "clipping":
|
case "clipping":
|
||||||
return ClippingAudioSource(
|
return ClippingAudioSource(
|
||||||
audioSource: AudioSource.fromJson(json['audioSource']),
|
child: AudioSource.fromJson(json['audioSource']),
|
||||||
start: Duration(milliseconds: json['start']),
|
start: Duration(milliseconds: json['start']),
|
||||||
end: Duration(milliseconds: json['end']));
|
end: Duration(milliseconds: json['end']));
|
||||||
default:
|
default:
|
||||||
|
@ -1025,25 +1025,25 @@ class HlsAudioSource extends UriAudioSource {
|
||||||
/// be played in succession. This can be used to create playlists. Audio sources
|
/// be played in succession. This can be used to create playlists. Audio sources
|
||||||
/// can be dynamically added, removed and reordered while the audio is playing.
|
/// can be dynamically added, removed and reordered while the audio is playing.
|
||||||
class ConcatenatingAudioSource extends AudioSource {
|
class ConcatenatingAudioSource extends AudioSource {
|
||||||
final List<AudioSource> audioSources;
|
final List<AudioSource> children;
|
||||||
final bool useLazyPreparation;
|
final bool useLazyPreparation;
|
||||||
|
|
||||||
ConcatenatingAudioSource({
|
ConcatenatingAudioSource({
|
||||||
@required this.audioSources,
|
@required this.children,
|
||||||
this.useLazyPreparation = false,
|
this.useLazyPreparation = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> _setup(AudioPlayer player) async {
|
Future<void> _setup(AudioPlayer player) async {
|
||||||
await super._setup(player);
|
await super._setup(player);
|
||||||
for (var source in audioSources) {
|
for (var source in children) {
|
||||||
await source._setup(player);
|
await source._setup(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Appends an [AudioSource].
|
/// Appends an [AudioSource].
|
||||||
Future<void> add(AudioSource audioSource) async {
|
Future<void> add(AudioSource audioSource) async {
|
||||||
audioSources.add(audioSource);
|
children.add(audioSource);
|
||||||
if (_player != null) {
|
if (_player != null) {
|
||||||
await _player
|
await _player
|
||||||
._invokeMethod('concatenating.add', [_id, audioSource.toJson()]);
|
._invokeMethod('concatenating.add', [_id, audioSource.toJson()]);
|
||||||
|
@ -1052,7 +1052,7 @@ class ConcatenatingAudioSource extends AudioSource {
|
||||||
|
|
||||||
/// Inserts an [AudioSource] at [index].
|
/// Inserts an [AudioSource] at [index].
|
||||||
Future<void> insert(int index, AudioSource audioSource) async {
|
Future<void> insert(int index, AudioSource audioSource) async {
|
||||||
audioSources.insert(index, audioSource);
|
children.insert(index, audioSource);
|
||||||
if (_player != null) {
|
if (_player != null) {
|
||||||
await _player._invokeMethod(
|
await _player._invokeMethod(
|
||||||
'concatenating.insert', [_id, index, audioSource.toJson()]);
|
'concatenating.insert', [_id, index, audioSource.toJson()]);
|
||||||
|
@ -1060,27 +1060,27 @@ class ConcatenatingAudioSource extends AudioSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Appends multiple [AudioSource]s.
|
/// Appends multiple [AudioSource]s.
|
||||||
Future<void> addAll(List<AudioSource> audioSources) async {
|
Future<void> addAll(List<AudioSource> children) async {
|
||||||
this.audioSources.addAll(audioSources);
|
this.children.addAll(children);
|
||||||
if (_player != null) {
|
if (_player != null) {
|
||||||
await _player._invokeMethod('concatenating.addAll',
|
await _player._invokeMethod('concatenating.addAll',
|
||||||
[_id, audioSources.map((s) => s.toJson()).toList()]);
|
[_id, children.map((s) => s.toJson()).toList()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert multiple [AudioSource]s at [index].
|
/// Insert multiple [AudioSource]s at [index].
|
||||||
Future<void> insertAll(int index, List<AudioSource> audioSources) async {
|
Future<void> insertAll(int index, List<AudioSource> children) async {
|
||||||
audioSources.insertAll(index, audioSources);
|
this.children.insertAll(index, children);
|
||||||
if (_player != null) {
|
if (_player != null) {
|
||||||
await _player._invokeMethod('concatenating.insertAll',
|
await _player._invokeMethod('concatenating.insertAll',
|
||||||
[_id, index, audioSources.map((s) => s.toJson()).toList()]);
|
[_id, index, children.map((s) => s.toJson()).toList()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dynmaically remove an [AudioSource] at [index] after this
|
/// Dynmaically remove an [AudioSource] at [index] after this
|
||||||
/// [ConcatenatingAudioSource] has already been loaded.
|
/// [ConcatenatingAudioSource] has already been loaded.
|
||||||
Future<void> removeAt(int index) async {
|
Future<void> removeAt(int index) async {
|
||||||
audioSources.removeAt(index);
|
children.removeAt(index);
|
||||||
if (_player != null) {
|
if (_player != null) {
|
||||||
await _player._invokeMethod('concatenating.removeAt', [_id, index]);
|
await _player._invokeMethod('concatenating.removeAt', [_id, index]);
|
||||||
}
|
}
|
||||||
|
@ -1089,7 +1089,7 @@ class ConcatenatingAudioSource extends AudioSource {
|
||||||
/// Removes a range of [AudioSource]s from index [start] inclusive to [end]
|
/// Removes a range of [AudioSource]s from index [start] inclusive to [end]
|
||||||
/// exclusive.
|
/// exclusive.
|
||||||
Future<void> removeRange(int start, int end) async {
|
Future<void> removeRange(int start, int end) async {
|
||||||
audioSources.removeRange(start, end);
|
children.removeRange(start, end);
|
||||||
if (_player != null) {
|
if (_player != null) {
|
||||||
await _player
|
await _player
|
||||||
._invokeMethod('concatenating.removeRange', [_id, start, end]);
|
._invokeMethod('concatenating.removeRange', [_id, start, end]);
|
||||||
|
@ -1098,7 +1098,7 @@ class ConcatenatingAudioSource extends AudioSource {
|
||||||
|
|
||||||
/// Moves an [AudioSource] from [currentIndex] to [newIndex].
|
/// Moves an [AudioSource] from [currentIndex] to [newIndex].
|
||||||
Future<void> move(int currentIndex, int newIndex) async {
|
Future<void> move(int currentIndex, int newIndex) async {
|
||||||
audioSources.insert(newIndex, audioSources.removeAt(currentIndex));
|
children.insert(newIndex, children.removeAt(currentIndex));
|
||||||
if (_player != null) {
|
if (_player != null) {
|
||||||
await _player
|
await _player
|
||||||
._invokeMethod('concatenating.move', [_id, currentIndex, newIndex]);
|
._invokeMethod('concatenating.move', [_id, currentIndex, newIndex]);
|
||||||
|
@ -1107,30 +1107,30 @@ class ConcatenatingAudioSource extends AudioSource {
|
||||||
|
|
||||||
/// Removes all [AudioSources].
|
/// Removes all [AudioSources].
|
||||||
Future<void> clear() async {
|
Future<void> clear() async {
|
||||||
audioSources.clear();
|
children.clear();
|
||||||
if (_player != null) {
|
if (_player != null) {
|
||||||
await _player._invokeMethod('concatenating.clear', [_id]);
|
await _player._invokeMethod('concatenating.clear', [_id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The number of [AudioSource]s.
|
/// The number of [AudioSource]s.
|
||||||
int get length => audioSources.length;
|
int get length => children.length;
|
||||||
|
|
||||||
operator [](int index) => audioSources[index];
|
operator [](int index) => children[index];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<IndexedAudioSource> get sequence =>
|
List<IndexedAudioSource> get sequence =>
|
||||||
audioSources.expand((s) => s.sequence).toList();
|
children.expand((s) => s.sequence).toList();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get _requiresHeaders =>
|
bool get _requiresHeaders =>
|
||||||
audioSources.any((source) => source._requiresHeaders);
|
children.any((source) => source._requiresHeaders);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map toJson() => {
|
Map toJson() => {
|
||||||
'id': _id,
|
'id': _id,
|
||||||
'type': 'concatenating',
|
'type': 'concatenating',
|
||||||
'audioSources': audioSources.map((source) => source.toJson()).toList(),
|
'audioSources': children.map((source) => source.toJson()).toList(),
|
||||||
'useLazyPreparation': useLazyPreparation,
|
'useLazyPreparation': useLazyPreparation,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1138,12 +1138,12 @@ class ConcatenatingAudioSource extends AudioSource {
|
||||||
/// An [AudioSource] that clips the audio of a [UriAudioSource] between a
|
/// An [AudioSource] that clips the audio of a [UriAudioSource] between a
|
||||||
/// certain start and end time.
|
/// certain start and end time.
|
||||||
class ClippingAudioSource extends IndexedAudioSource {
|
class ClippingAudioSource extends IndexedAudioSource {
|
||||||
final UriAudioSource audioSource;
|
final UriAudioSource child;
|
||||||
final Duration start;
|
final Duration start;
|
||||||
final Duration end;
|
final Duration end;
|
||||||
|
|
||||||
ClippingAudioSource({
|
ClippingAudioSource({
|
||||||
@required this.audioSource,
|
@required this.child,
|
||||||
this.start,
|
this.start,
|
||||||
this.end,
|
this.end,
|
||||||
Object tag,
|
Object tag,
|
||||||
|
@ -1152,17 +1152,17 @@ class ClippingAudioSource extends IndexedAudioSource {
|
||||||
@override
|
@override
|
||||||
Future<void> _setup(AudioPlayer player) async {
|
Future<void> _setup(AudioPlayer player) async {
|
||||||
await super._setup(player);
|
await super._setup(player);
|
||||||
await audioSource._setup(player);
|
await child._setup(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get _requiresHeaders => audioSource._requiresHeaders;
|
bool get _requiresHeaders => child._requiresHeaders;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map toJson() => {
|
Map toJson() => {
|
||||||
'id': _id,
|
'id': _id,
|
||||||
'type': 'clipping',
|
'type': 'clipping',
|
||||||
'audioSource': audioSource.toJson(),
|
'audioSource': child.toJson(),
|
||||||
'start': start?.inMilliseconds,
|
'start': start?.inMilliseconds,
|
||||||
'end': end?.inMilliseconds,
|
'end': end?.inMilliseconds,
|
||||||
};
|
};
|
||||||
|
@ -1171,28 +1171,26 @@ class ClippingAudioSource extends IndexedAudioSource {
|
||||||
// An [AudioSource] that loops a nested [AudioSource] a
|
// An [AudioSource] that loops a nested [AudioSource] a
|
||||||
// specified number of times.
|
// specified number of times.
|
||||||
class LoopingAudioSource extends AudioSource {
|
class LoopingAudioSource extends AudioSource {
|
||||||
AudioSource audioSource;
|
AudioSource child;
|
||||||
final int count;
|
final int count;
|
||||||
|
|
||||||
LoopingAudioSource({
|
LoopingAudioSource({
|
||||||
@required this.audioSource,
|
@required this.child,
|
||||||
this.count,
|
this.count,
|
||||||
}) : super();
|
}) : super();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<IndexedAudioSource> get sequence =>
|
List<IndexedAudioSource> get sequence =>
|
||||||
List.generate(count, (i) => audioSource)
|
List.generate(count, (i) => child).expand((s) => s.sequence).toList();
|
||||||
.expand((s) => s.sequence)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get _requiresHeaders => audioSource._requiresHeaders;
|
bool get _requiresHeaders => child._requiresHeaders;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map toJson() => {
|
Map toJson() => {
|
||||||
'id': _id,
|
'id': _id,
|
||||||
'type': 'looping',
|
'type': 'looping',
|
||||||
'audioSource': audioSource.toJson(),
|
'audioSource': child.toJson(),
|
||||||
'count': count,
|
'count': count,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue