-
Notifications
You must be signed in to change notification settings - Fork 823
/
source.dart
79 lines (62 loc) · 1.81 KB
/
source.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import 'dart:typed_data';
import 'package:audioplayers/src/audioplayer.dart';
/// A generic representation of a source from where audio can be pulled.
///
/// This can be a remote or local URL, an application asset, or the file bytes.
abstract class Source {
Future<void> setOnPlayer(AudioPlayer player);
}
/// Source representing a remote URL to be played from the Internet.
/// This can be an audio file to be downloaded or an audio stream.
class UrlSource extends Source {
final String url;
UrlSource(this.url);
@override
Future<void> setOnPlayer(AudioPlayer player) {
return player.setSourceUrl(url);
}
@override
String toString() {
return 'UrlSource(url: $url)';
}
}
/// Source representing the absolute path of a file in the user's device.
class DeviceFileSource extends Source {
final String path;
DeviceFileSource(this.path);
@override
Future<void> setOnPlayer(AudioPlayer player) {
return player.setSourceDeviceFile(path);
}
@override
String toString() {
return 'DeviceFileSource(path: $path)';
}
}
/// Source representing the path of an application asset in your Flutter
/// "assets" folder.
/// Note that a prefix might be applied by your [AudioPlayer]'s audio cache
/// instance.
class AssetSource extends Source {
final String path;
AssetSource(this.path);
@override
Future<void> setOnPlayer(AudioPlayer player) {
return player.setSourceAsset(path);
}
@override
String toString() {
return 'AssetSource(path: $path)';
}
}
/// Source containing the actual bytes of the media to be played.
///
/// This is currently only supported for Android (SDK >= 23).
class BytesSource extends Source {
final Uint8List bytes;
BytesSource(this.bytes);
@override
Future<void> setOnPlayer(AudioPlayer player) {
return player.setSourceBytes(bytes);
}
}