Caijinglong před 6 roky
rodič
revize
fa9f19f3c8

+ 21 - 1
LICENSE

@@ -1 +1,21 @@
-TODO: Add your license here.
+MIT License
+
+Copyright (c) 2019 Caijinglong
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 60 - 2
README.md

@@ -2,9 +2,60 @@
 
 ijkplayer,通过纹理的方式接入 bilibili/ijkplayer
 
+使用前请完整阅读本README并参阅 example/lib/main.dart
+
+有关android跑不起来的问题会详细解释
+
+## About English Readme
+
+At present, it is a preview version, which can be easily used without providing English documents for the time being.
+English documents will be provided after the main objectives have been completed.
+
+待主要目标完成后再提供英文文档
+
+## Install
+
+pubspec.yaml  
+
+```yaml
+dependencies:
+  flutter_ijkplayer: ^0.0.1 
+```
+
+## Build
+
+编译规则可以参考这个,如果你有自己的特定需求,可以修改编译选项,这个参考bilibili/ijkplayer或ffmpeg
+
+https://github.com/CaiJingLong/flutter_ijkplayer_pod/blob/master/config/module.sh
+
+### iOS
+
+因为iOS部分代码的库文件比较大,所以创建了一个pod依赖托管iOS的ijkplayer库  
+pod库托管在github 仓库内 https://github.com/CaiJingLong/flutter_ijkplayer_pod  
+没有采用通用的tar.gz或zip,而是使用tar.xz的方式压缩,这个压缩格式压缩率高,但是压缩和解压缩的的速度慢,综合考虑使用高压缩率的方式  
+如果有朋友愿意提供全球cdn加速,可以联系我😁
+  
+iOS的代码来自于 https://github.com/jadennn/flutter_ijk 中的iOS代码  
+在这基础上增加了旋转通知
+
+### Android
+
+和iOS不同,这个没有修改,而是使用bilibili的0.8.8版+openssl编译的so库
+
+构建时可能会报错,或者闪退,这个是因为so库的问题
+
+vscode: 你需要修改.vscode/launch.json
+添加 `"args": ["--target-platform", "android-arm"]`
+
+android studio: 你需要点击run左边那个main.dart=>Edit Configurations,然后在Additional Arguments中添加 `--target-platform android-arm`
+
+打包时同理,尽量只保留armv7就可以了
+
+如果你使用模拟器开发,就把参数替换为android-x86,目标机型参阅`flutter run -h` `--target-platform`内的介绍
+
 ## Progress
 
-目前正处于初始开发阶段
+目前正处于初始开发阶段,可能有各种问题,欢迎提出
 
 最初准备参考官方video_player的api方式进行开发,但是觉得调用的方式比较奇怪
 
@@ -17,4 +68,11 @@ ijkplayer,通过纹理的方式接入 bilibili/ijkplayer
 - [ ] 默认控制器UI
 
   - [ ] 纵向
-  - [ ] 横向
+  - [ ] 横向
+
+初版为预览版,不保证质量
+UI
+
+## LICENSE
+
+MIT

+ 1 - 0
android/src/main/java/top/kikt/ijkplayer/NotifyChannel.kt

@@ -46,6 +46,7 @@ class NotifyChannel(val registry: PluginRegistry.Registrar, val textureId: Long,
                 }
                 IMediaPlayer.MEDIA_INFO_VIDEO_ROTATION_CHANGED -> {
                     ijk.degree = extra
+                    channel.invokeMethod("rotateChanged", info)
                 }
             }
             false

+ 4 - 4
example/ios/Podfile.lock

@@ -2,8 +2,8 @@ PODS:
   - Flutter (1.0.0)
   - flutter_ijkplayer (0.0.1):
     - Flutter
-    - FlutterIJK (~> 0.0.3)
-  - FlutterIJK (0.0.3)
+    - FlutterIJK (~> 0.0.6)
+  - FlutterIJK (0.0.6)
   - photo_manager (0.0.1):
     - Flutter
 
@@ -26,8 +26,8 @@ EXTERNAL SOURCES:
 
 SPEC CHECKSUMS:
   Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
-  flutter_ijkplayer: 8e0761718c08711f50a86aaa3ca0ce0655ea3462
-  FlutterIJK: 593a48952fb5022fb5c0bd8bd26fd1a11418ce5c
+  flutter_ijkplayer: 6e17431ef86df3ab4c9e8acf91a34d174a20d3db
+  FlutterIJK: fef71db3a6d8d26b32e793cd9c2cf30b3ca56b4d
   photo_manager: d47ddf6cb25cbfa837dc334540eb9a99b208e191
 
 PODFILE CHECKSUM: a14c63eb48a9d676ed6d876506b3258fd9c85235

+ 2 - 0
ios/Classes/CoolFlutterIJK.m

@@ -232,6 +232,8 @@
     return info;
 }
 
+
+
 - (NSUInteger)degreeFromVideoFileWithURL:(NSURL *)url {
     NSUInteger mDegree = 0;
 

+ 2 - 0
ios/Classes/CoolIjkNotifyChannel.h

@@ -10,6 +10,8 @@
 
 @protocol KKIjkNotifyDelegate
 - (CoolVideoInfo *)getInfo;
+
+- (void)setDegree:(int)newDegree;
 @end
 
 @interface CoolIjkNotifyChannel : NSObject

+ 15 - 0
ios/Classes/CoolIjkNotifyChannel.m

@@ -60,6 +60,11 @@
                                              selector:@selector(moviePlayBackStateDidChange:)
                                                  name:IJKMPMoviePlayerPlaybackStateDidChangeNotification
                                                object:_controller];
+
+    [[NSNotificationCenter defaultCenter] addObserver:self
+                                             selector:@selector(movieRotationChange:)
+                                                 name:IJKMPMoviePlayerVideoRotationNotification
+                                               object:_controller];
 }
 
 - (void)unregisterObservers {
@@ -75,6 +80,9 @@
     [[NSNotificationCenter defaultCenter] removeObserver:self
                                                     name:IJKMPMoviePlayerPlaybackStateDidChangeNotification
                                                   object:_controller];
+    [[NSNotificationCenter defaultCenter] removeObserver:self
+                                                    name:IJKMPMoviePlayerVideoRotationNotification
+                                                  object:_controller];
 }
 
 - (NSDictionary *)getInfo {
@@ -89,6 +97,7 @@
     [channel invokeMethod:@"prepare" arguments:[self getInfo]];
 }
 
+
 - (void)moviePlayBackFinish:(NSNotification *)notification {
 //    int reason = [[[notification userInfo] valueForKey:IJKMPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
 //    int type = 2;
@@ -112,4 +121,10 @@
 //    [channel invokeMethod:@"loadStateChange" arguments:[self getInfo]];
 }
 
+- (void)movieRotationChange:(NSNotification *)notification {
+    int rotate = [[[notification userInfo] valueForKey:IJKMPMoviePlayerVideoRotationRotateUserInfoKey] intValue];
+    [_infoDelegate setDegree:rotate];
+    [channel invokeMethod:@"rotateChanged" arguments:[self getInfo]];
+}
+
 @end

+ 1 - 1
ios/flutter_ijkplayer.podspec

@@ -18,7 +18,7 @@ A new flutter plugin project.
 
   s.ios.deployment_target = '8.0'
 
-  s.dependency 'FlutterIJK', '~> 0.0.3'
+  s.dependency 'FlutterIJK', '~> 0.0.6'
 
 end
 

+ 1 - 0
lib/src/controller.dart

@@ -162,6 +162,7 @@ class IjkMediaController {
     var info = await getVideoInfo();
     isPlaying = info.isPlaying;
     if (info.hasData) _videoInfoController.add(info);
+    print("info = $info");
   }
 
   void _autoPlay(bool autoPlay) {

+ 10 - 1
lib/src/ijk_event_channel.dart

@@ -1,8 +1,9 @@
+import 'dart:async';
+
 import 'package:flutter/services.dart';
 import 'package:flutter_ijkplayer/src/video_info.dart';
 
 import './ijkplayer.dart';
-import 'dart:async';
 
 class IJKEventChannel {
   int get textureId => controller?.textureId;
@@ -40,6 +41,9 @@ class IJKEventChannel {
       case "prepare":
         onPrepare(getInfo(call));
         break;
+      case "rotateChanged":
+        onRotateChanged(call);
+        break;
       default:
         return MissingPluginException(
           "$channelName ${call.method} not implement",
@@ -80,6 +84,11 @@ class IJKEventChannel {
       print(e);
     }
   }
+
+  void onRotateChanged(MethodCall call) {
+    var info = getInfo(call);
+    print("onRotateChanged , info = $info");
+  }
 }
 
 // enum FinishType {

+ 27 - 1
lib/src/widget/controller.dart

@@ -36,20 +36,46 @@ class _DefaultControllerWidgetState extends State<DefaultControllerWidget> {
 
   Timer progressTimer;
 
+  StreamSubscription controllerSubscription;
+
   @override
   void initState() {
     super.initState();
     startTimer();
+    controllerSubscription = controller.textureIdStream.listen(_onTextIdChange);
+  }
+
+  void _onTextIdChange(int textId) {
+    if (textId != null) {
+      startTimer();
+    } else {
+      stopTimer();
+    }
   }
 
   @override
-  void dispose() {
+  void deactivate() {
+    super.deactivate();
+    controllerSubscription.cancel();
     stopTimer();
+  }
+
+  @override
+  void dispose() {
     super.dispose();
   }
 
   void startTimer() {
+    if (controller.textureId == null) {
+      return;
+    }
+
     progressTimer?.cancel();
+    controller.videoInfoStream.listen((info) {
+      if (info == null || !info.hasData) {
+        stopTimer();
+      }
+    });
     progressTimer = Timer.periodic(Duration(milliseconds: 400), (timer) {
       controller.refreshVideoInfo();
     });