fix: 关闭自动播放时播放器初始化逻辑、播放器插件回滚(高版本页面回退时不会自动继续播放)
This commit is contained in:
@ -41,7 +41,6 @@ class VideoDetailController extends GetxController
|
|||||||
late VideoQuality currentVideoQa;
|
late VideoQuality currentVideoQa;
|
||||||
AudioQuality? currentAudioQa;
|
AudioQuality? currentAudioQa;
|
||||||
late VideoDecodeFormats currentDecodeFormats;
|
late VideoDecodeFormats currentDecodeFormats;
|
||||||
// PlPlayerController plPlayerController = PlPlayerController();
|
|
||||||
// 是否开始自动播放 存在多p的情况下,第二p需要为true
|
// 是否开始自动播放 存在多p的情况下,第二p需要为true
|
||||||
RxBool autoPlay = true.obs;
|
RxBool autoPlay = true.obs;
|
||||||
// 视频资源是否有效
|
// 视频资源是否有效
|
||||||
@ -183,7 +182,6 @@ class VideoDetailController extends GetxController
|
|||||||
),
|
),
|
||||||
// 硬解
|
// 硬解
|
||||||
enableHA: enableHA.value,
|
enableHA: enableHA.value,
|
||||||
autoplay: autoPlay.value,
|
|
||||||
seekTo: seekToTime ?? defaultST,
|
seekTo: seekToTime ?? defaultST,
|
||||||
duration: duration ?? Duration(milliseconds: data.timeLength ?? 0),
|
duration: duration ?? Duration(milliseconds: data.timeLength ?? 0),
|
||||||
// 宽>高 水平 否则 垂直
|
// 宽>高 水平 否则 垂直
|
||||||
@ -198,11 +196,6 @@ class VideoDetailController extends GetxController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手动点击播放
|
|
||||||
handlePlay() {
|
|
||||||
plPlayerController.togglePlay();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 视频链接
|
// 视频链接
|
||||||
Future queryVideoUrl() async {
|
Future queryVideoUrl() async {
|
||||||
var result = await VideoHttp.videoUrl(cid: cid, bvid: bvid);
|
var result = await VideoHttp.videoUrl(cid: cid, bvid: bvid);
|
||||||
@ -292,7 +285,9 @@ class VideoDetailController extends GetxController
|
|||||||
currentAudioQa = AudioQualityCode.fromCode(firstAudio.id!)!;
|
currentAudioQa = AudioQualityCode.fromCode(firstAudio.id!)!;
|
||||||
}
|
}
|
||||||
defaultST = Duration(milliseconds: data.lastPlayTime!);
|
defaultST = Duration(milliseconds: data.lastPlayTime!);
|
||||||
await playerInit();
|
if (autoPlay.value) {
|
||||||
|
await playerInit();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (result['code'] == -404) {
|
if (result['code'] == -404) {
|
||||||
isShowCover.value = false;
|
isShowCover.value = false;
|
||||||
|
@ -53,20 +53,29 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
plPlayerController = videoDetailController.plPlayerController;
|
statusBarHeight = localCache.get('statusBarHeight');
|
||||||
playerListener();
|
videoSourceInit();
|
||||||
|
appbarStreamListen();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取视频资源,初始化播放器
|
||||||
|
Future<void> videoSourceInit() async {
|
||||||
|
_futureBuilderFuture = videoDetailController.queryVideoUrl();
|
||||||
|
if (videoDetailController.autoPlay.value) {
|
||||||
|
plPlayerController = videoDetailController.plPlayerController;
|
||||||
|
playerListener();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 流
|
||||||
|
appbarStreamListen() {
|
||||||
appbarStream = StreamController<double>();
|
appbarStream = StreamController<double>();
|
||||||
|
|
||||||
_extendNestCtr.addListener(
|
_extendNestCtr.addListener(
|
||||||
() {
|
() {
|
||||||
double offset = _extendNestCtr.position.pixels;
|
double offset = _extendNestCtr.position.pixels;
|
||||||
appbarStream.add(offset);
|
appbarStream.add(offset);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
statusBarHeight = localCache.get('statusBarHeight');
|
|
||||||
_futureBuilderFuture = videoDetailController.queryVideoUrl();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 播放器状态监听
|
// 播放器状态监听
|
||||||
@ -96,6 +105,14 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
plPlayerController!.play();
|
plPlayerController!.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> handlePlay() async {
|
||||||
|
await videoDetailController.playerInit();
|
||||||
|
plPlayerController = videoDetailController.plPlayerController;
|
||||||
|
videoDetailController.autoPlay.value = true;
|
||||||
|
videoDetailController.isShowCover.value = false;
|
||||||
|
playerListener();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
plPlayerController!.dispose();
|
plPlayerController!.dispose();
|
||||||
@ -179,13 +196,20 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
builder: ((context, snapshot) {
|
builder: ((context, snapshot) {
|
||||||
if (snapshot.hasData &&
|
if (snapshot.hasData &&
|
||||||
snapshot.data['status']) {
|
snapshot.data['status']) {
|
||||||
return PLVideoPlayer(
|
return Obx(
|
||||||
controller: plPlayerController!,
|
() => videoDetailController
|
||||||
headerControl: HeaderControl(
|
.autoPlay.value
|
||||||
controller: plPlayerController,
|
? PLVideoPlayer(
|
||||||
videoDetailCtr:
|
controller:
|
||||||
videoDetailController,
|
plPlayerController!,
|
||||||
),
|
headerControl: HeaderControl(
|
||||||
|
controller:
|
||||||
|
plPlayerController,
|
||||||
|
videoDetailCtr:
|
||||||
|
videoDetailController,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const SizedBox(),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
@ -228,28 +252,31 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
right: 0,
|
right: 0,
|
||||||
child: AppBar(
|
child: AppBar(
|
||||||
primary: false,
|
primary: false,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
Colors.transparent,
|
Colors.transparent,
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: '稍后再看',
|
tooltip: '稍后再看',
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
var res = await UserHttp
|
var res = await UserHttp
|
||||||
.toViewLater(
|
.toViewLater(
|
||||||
bvid:
|
bvid:
|
||||||
videoDetailController
|
videoDetailController
|
||||||
.bvid);
|
.bvid);
|
||||||
SmartDialog.showToast(
|
SmartDialog.showToast(
|
||||||
res['msg']);
|
res['msg']);
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons
|
icon: const Icon(
|
||||||
.history_outlined))
|
Icons.history_outlined),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 14)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Positioned(
|
Positioned(
|
||||||
right: 12,
|
right: 12,
|
||||||
bottom: 6,
|
bottom: 10,
|
||||||
child: TextButton.icon(
|
child: TextButton.icon(
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
@ -261,9 +288,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
.primaryContainer;
|
.primaryContainer;
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
onPressed: () =>
|
onPressed: () => handlePlay(),
|
||||||
videoDetailController
|
|
||||||
.handlePlay(),
|
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
Icons.play_circle_outline,
|
Icons.play_circle_outline,
|
||||||
size: 20,
|
size: 20,
|
||||||
|
20
pubspec.lock
20
pubspec.lock
@ -726,7 +726,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.6"
|
version: "1.1.6"
|
||||||
media_kit_libs_android_video:
|
media_kit_libs_android_video:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: media_kit_libs_android_video
|
name: media_kit_libs_android_video
|
||||||
sha256: "498a5062bc5f000bd23ada3be788ea886ab32c52f7a8252dde1264ca019b819b"
|
sha256: "498a5062bc5f000bd23ada3be788ea886ab32c52f7a8252dde1264ca019b819b"
|
||||||
@ -734,7 +734,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.3"
|
version: "1.3.3"
|
||||||
media_kit_libs_ios_video:
|
media_kit_libs_ios_video:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: media_kit_libs_ios_video
|
name: media_kit_libs_ios_video
|
||||||
sha256: fed403dc9d54462e51ee80e0cb23c12a53fadea9a8fa18aca2de9054176d1159
|
sha256: fed403dc9d54462e51ee80e0cb23c12a53fadea9a8fa18aca2de9054176d1159
|
||||||
@ -742,7 +742,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.3"
|
version: "1.1.3"
|
||||||
media_kit_libs_linux:
|
media_kit_libs_linux:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: media_kit_libs_linux
|
name: media_kit_libs_linux
|
||||||
sha256: "3b7c272179639a914dc8a50bf8a3f2df0e9a503bd727c88fab499dbdf6cb1eb8"
|
sha256: "3b7c272179639a914dc8a50bf8a3f2df0e9a503bd727c88fab499dbdf6cb1eb8"
|
||||||
@ -750,23 +750,15 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.2"
|
version: "1.1.2"
|
||||||
media_kit_libs_macos_video:
|
media_kit_libs_macos_video:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: media_kit_libs_macos_video
|
name: media_kit_libs_macos_video
|
||||||
sha256: c06e831f3c22a45296d375788d9bc07871b448f8e9ec98d77b11e5e118a83fb2
|
sha256: c06e831f3c22a45296d375788d9bc07871b448f8e9ec98d77b11e5e118a83fb2
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.3"
|
version: "1.1.3"
|
||||||
media_kit_libs_video:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: media_kit_libs_video
|
|
||||||
sha256: "48c8ace458f340e6b930c89c48141ea727b80aa0878f7a01904d7d439865f162"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.0"
|
|
||||||
media_kit_libs_windows_video:
|
media_kit_libs_windows_video:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: media_kit_libs_windows_video
|
name: media_kit_libs_windows_video
|
||||||
sha256: "923f068344d7d200184e0aaa2597f3de6c05982a3b1f18035d842ab53f2a1350"
|
sha256: "923f068344d7d200184e0aaa2597f3de6c05982a3b1f18035d842ab53f2a1350"
|
||||||
@ -774,7 +766,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.8"
|
version: "1.0.8"
|
||||||
media_kit_native_event_loop:
|
media_kit_native_event_loop:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: media_kit_native_event_loop
|
name: media_kit_native_event_loop
|
||||||
sha256: e37ce6fb5fa71b8cf513c6a6cd591367743a342a385e7da621a047dd8ef6f4a4
|
sha256: e37ce6fb5fa71b8cf513c6a6cd591367743a342a385e7da621a047dd8ef6f4a4
|
||||||
|
11
pubspec.yaml
11
pubspec.yaml
@ -84,9 +84,14 @@ dependencies:
|
|||||||
crypto: ^3.0.3
|
crypto: ^3.0.3
|
||||||
|
|
||||||
# 视频播放器
|
# 视频播放器
|
||||||
media_kit: ^1.1.6
|
media_kit: ^1.1.4 # Primary package.
|
||||||
media_kit_video: ^1.1.7
|
media_kit_video: ^1.1.5 # For video rendering.
|
||||||
media_kit_libs_video: ^1.0.0
|
media_kit_native_event_loop: ^1.0.7 # Support for higher number of concurrent instances & better performance.
|
||||||
|
media_kit_libs_android_video: ^1.3.2 # Android package for video native libraries.
|
||||||
|
media_kit_libs_ios_video: ^1.1.3 # iOS package for video native libraries.
|
||||||
|
media_kit_libs_macos_video: ^1.1.3 # macOS package for video native libraries.
|
||||||
|
media_kit_libs_windows_video: ^1.0.7 # Windows package for video native libraries.
|
||||||
|
media_kit_libs_linux: ^1.1.1
|
||||||
|
|
||||||
# 音量、亮度、屏幕控制
|
# 音量、亮度、屏幕控制
|
||||||
flutter_volume_controller: ^1.2.7
|
flutter_volume_controller: ^1.2.7
|
||||||
|
Reference in New Issue
Block a user