瀏覽代碼

完善了几处示例代码

cjl_macbook 6 年之前
父節點
當前提交
57aaa5ef8a

+ 1 - 1
example/lib/page/index.dart

@@ -22,7 +22,7 @@ class _IndexPageState extends State<IndexPage> {
           buildButton("播放网络视频", NetworkPage()),
           buildButton("播放相册视频", PlayGalleryPage()),
           buildButton("播放应用asset", AssetPage()),
-          buildButton("ListView中插入视频", VideoList()),
+          buildButton("ListView中插入视频(未完成)", VideoList()),
           buildButton("全屏切换示例", FullScreen()),
         ],
       ),

+ 3 - 3
example/lib/page/video_list.dart

@@ -55,9 +55,9 @@ class _VideoListState extends State<VideoList> {
   }
 
   Widget _buildItem(BuildContext context, int index) {
-    return Container(
+    return AspectRatio(
       child: VideoItem(list[index]),
-      height: 150,
+      aspectRatio: 1280 / 500,
     );
   }
 }
@@ -132,7 +132,7 @@ class _VideoItemState extends State<VideoItem> {
       isLoading = true;
     });
     await controller.setDataSource(widget.dataSource, autoPlay: true);
-    await controller.pauseOtherIjkMedia();
+    await controller.pauseOtherController();
     setState(() {
       isLoading = false;
       isInit = true;

+ 12 - 4
lib/src/controller.dart

@@ -207,13 +207,21 @@ class IjkMediaController {
     if (playing) {
       await _plugin?.pause();
     } else {
-      await _plugin?.play(pauseOther: pauseOther);
+      if (pauseOther) {
+        await pauseOtherController();
+      }
+      await _plugin?.play();
     }
     refreshVideoInfo();
   }
 
   /// play media
-  Future<void> play() async {
+  Future<void> play({
+    pauseOther = false,
+  }) async {
+    if (pauseOther) {
+      await pauseOtherController();
+    }
     await _plugin?.play();
     refreshVideoInfo();
   }
@@ -287,7 +295,7 @@ class IjkMediaController {
     await IjkManager.setSystemVolume(volume);
   }
 
-  Future<void> pauseOtherIjkMedia() async {
+  Future<void> pauseOtherController() async {
     await IjkMediaPlayerManager().pauseOther(this);
   }
 }
@@ -312,7 +320,7 @@ class _IjkPlugin {
     await _globalChannel.invokeMethod("dispose", {"id": textureId});
   }
 
-  Future<void> play({bool pauseOther = false}) async {
+  Future<void> play() async {
     await channel.invokeMethod("play");
   }
 

+ 4 - 12
lib/src/engine/ijk_controller_manager.dart

@@ -21,18 +21,10 @@ class IjkMediaPlayerManager {
   }
 
   Future<void> pauseOther(IjkMediaController ijkMediaController) async {
-    await todoOther(ijkMediaController, (ctl) {
-      ctl.pause();
-    });
-  }
-
-  Future<void> todoOther(
-    IjkMediaController ijkMediaController,
-    Future<void> todo(IjkMediaController ijkMediaController),
-  ) async {
-    for (var item in ijkPlayerList) {
-      if (item != ijkMediaController) {
-        await todo(item);
+    for (var ctl in this.ijkPlayerList) {
+      if (ctl != ijkMediaController) {
+        print("ctl ${ctl.textureId} will pause");
+        ctl.pause();
       }
     }
   }

+ 7 - 1
lib/src/widget/controller_widget_builder.dart

@@ -37,6 +37,8 @@ class DefaultControllerWidget extends StatefulWidget {
   /// Controlling [verticalGesture] is controlling system volume or media volume.
   final VolumeType volumeType;
 
+  final bool playWillPauseOther;
+
   /// The UI of the controller.
   const DefaultControllerWidget({
     @required this.controller,
@@ -44,6 +46,7 @@ class DefaultControllerWidget extends StatefulWidget {
     this.verticalGesture = true,
     this.horizontalGesture = true,
     this.volumeType = VolumeType.system,
+    this.playWillPauseOther = true,
   });
 
   @override
@@ -152,6 +155,7 @@ class _DefaultControllerWidgetState extends State<DefaultControllerWidget>
       controller: controller,
       info: info,
       tooltipDelegate: this,
+      playWillPauseOther: widget.playWillPauseOther,
     );
   }
 
@@ -364,12 +368,14 @@ class PortraitController extends StatelessWidget {
   final IjkMediaController controller;
   final VideoInfo info;
   final TooltipDelegate tooltipDelegate;
+  final bool playWillPauseOther;
 
   const PortraitController({
     Key key,
     this.controller,
     this.info,
     this.tooltipDelegate,
+    this.playWillPauseOther = true,
   }) : super(key: key);
 
   bool get haveTime {
@@ -465,7 +471,7 @@ class PortraitController extends StatelessWidget {
   buildPlayButton(BuildContext context) {
     return IconButton(
       onPressed: () {
-        controller.playOrPause();
+        controller.playOrPause(pauseOther: playWillPauseOther);
       },
       color: Colors.white,
       icon: Icon(info.isPlaying ? Icons.pause : Icons.play_arrow),