|
@@ -13,12 +13,21 @@ class IjkMediaController extends ChangeNotifier {
|
|
|
|
|
|
|
|
bool _isPlaying = false;
|
|
bool _isPlaying = false;
|
|
|
|
|
|
|
|
- bool get isPlaying => _isPlaying;
|
|
|
|
|
|
|
+ bool get isPlaying => _isPlaying == true;
|
|
|
|
|
|
|
|
set isPlaying(bool value) {
|
|
set isPlaying(bool value) {
|
|
|
this._isPlaying = value;
|
|
this._isPlaying = value;
|
|
|
|
|
+ _playingController.add(value);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ StreamController<bool> _playingController = StreamController.broadcast();
|
|
|
|
|
+
|
|
|
|
|
+ Stream<bool> get playingStream => _playingController.stream;
|
|
|
|
|
+
|
|
|
|
|
+ StreamController<VideoInfo> _videoInfoController = StreamController.broadcast();
|
|
|
|
|
+
|
|
|
|
|
+ Stream<VideoInfo> get videoInfoStream => _videoInfoController.stream;
|
|
|
|
|
+
|
|
|
Future<void> _initIjk() async {
|
|
Future<void> _initIjk() async {
|
|
|
try {
|
|
try {
|
|
|
var id = await _createIjk();
|
|
var id = await _createIjk();
|
|
@@ -32,14 +41,20 @@ class IjkMediaController extends ChangeNotifier {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void dispose() {
|
|
|
|
|
|
|
+ void dispose() async {
|
|
|
|
|
+ await reset();
|
|
|
|
|
+ _playingController.close();
|
|
|
|
|
+ _videoInfoController.close();
|
|
|
|
|
+ super.dispose();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Future<void> reset() async {
|
|
|
this.textureId = null;
|
|
this.textureId = null;
|
|
|
this.notifyListeners();
|
|
this.notifyListeners();
|
|
|
_plugin?.dispose();
|
|
_plugin?.dispose();
|
|
|
_plugin = null;
|
|
_plugin = null;
|
|
|
eventChannel?.dispose();
|
|
eventChannel?.dispose();
|
|
|
eventChannel = null;
|
|
eventChannel = null;
|
|
|
- super.dispose();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Future<void> setNetworkDataSource(
|
|
Future<void> setNetworkDataSource(
|
|
@@ -86,38 +101,46 @@ class IjkMediaController extends ChangeNotifier {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Future<void> playOrPause() async {
|
|
Future<void> playOrPause() async {
|
|
|
- var playing = isPlaying == true;
|
|
|
|
|
|
|
+ var videoInfo = await getVideoInfo();
|
|
|
|
|
+ print(videoInfo);
|
|
|
|
|
+
|
|
|
|
|
+ var playing = videoInfo.isPlaying;
|
|
|
if (playing) {
|
|
if (playing) {
|
|
|
await _plugin?.pause();
|
|
await _plugin?.pause();
|
|
|
- playing = false;
|
|
|
|
|
} else {
|
|
} else {
|
|
|
await _plugin?.play();
|
|
await _plugin?.play();
|
|
|
- playing = true;
|
|
|
|
|
}
|
|
}
|
|
|
- this.notifyListeners();
|
|
|
|
|
|
|
+ refreshVideoInfo();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Future<void> play() async {
|
|
Future<void> play() async {
|
|
|
await _plugin?.play();
|
|
await _plugin?.play();
|
|
|
- this.notifyListeners();
|
|
|
|
|
|
|
+ refreshVideoInfo();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Future<void> pause() async {
|
|
Future<void> pause() async {
|
|
|
await _plugin?.pause();
|
|
await _plugin?.pause();
|
|
|
- this.notifyListeners();
|
|
|
|
|
|
|
+ refreshVideoInfo();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Future<void> seekTo(double target) async {
|
|
Future<void> seekTo(double target) async {
|
|
|
await _plugin?.seekTo(target);
|
|
await _plugin?.seekTo(target);
|
|
|
|
|
+ refreshVideoInfo();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Future<VideoInfo> getVideoInfo() async {
|
|
Future<VideoInfo> getVideoInfo() async {
|
|
|
Map<String, dynamic> result = await _plugin?.getInfo();
|
|
Map<String, dynamic> result = await _plugin?.getInfo();
|
|
|
var info = VideoInfo.fromMap(result);
|
|
var info = VideoInfo.fromMap(result);
|
|
|
- isPlaying = info.isPlaying;
|
|
|
|
|
return info;
|
|
return info;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ Future<void> refreshVideoInfo() async {
|
|
|
|
|
+ var info = await getVideoInfo();
|
|
|
|
|
+ isPlaying = info.isPlaying;
|
|
|
|
|
+ _videoInfoController.add(info);
|
|
|
|
|
+ this.notifyListeners();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
void _autoPlay(bool autoPlay) {
|
|
void _autoPlay(bool autoPlay) {
|
|
|
if (autoPlay) {
|
|
if (autoPlay) {
|
|
|
eventChannel.autoPlay(this);
|
|
eventChannel.autoPlay(this);
|
|
@@ -125,9 +148,11 @@ class IjkMediaController extends ChangeNotifier {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Future<void> stop() async {
|
|
Future<void> stop() async {
|
|
|
- await _plugin?.stop();
|
|
|
|
|
- isPlaying = false;
|
|
|
|
|
- this.notifyListeners();
|
|
|
|
|
|
|
+// await _plugin?.stop();
|
|
|
|
|
+// refreshVideoInfo();
|
|
|
|
|
+ await _plugin.pause();
|
|
|
|
|
+ await _plugin.seekTo(0);
|
|
|
|
|
+ refreshVideoInfo();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|