Unverified 提交 469d52b1 authored 作者: Dokieyang's avatar Dokieyang 提交者: GitHub

Merge pull request #13 from 673697831/main

SuperPlayerView添加进入全屏,退出全屏,返回按钮通知
package com.example.super_player; package com.example.super_player;
import android.content.Context; import android.content.Context;
import android.os.Bundle;
import android.view.View; import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
...@@ -12,8 +13,10 @@ import com.tencent.liteav.demo.superplayer.SuperPlayerView; ...@@ -12,8 +13,10 @@ import com.tencent.liteav.demo.superplayer.SuperPlayerView;
import com.tencent.rtmp.TXLiveBase; import com.tencent.rtmp.TXLiveBase;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.EventChannel; import io.flutter.plugin.common.EventChannel;
...@@ -90,12 +93,12 @@ public class SuperPlatformPlayerView implements PlatformView, MethodChannel.Meth ...@@ -90,12 +93,12 @@ public class SuperPlatformPlayerView implements PlatformView, MethodChannel.Meth
@Override @Override
public void onStartFullScreenPlay() { public void onStartFullScreenPlay() {
mEventSink.success("onStartFullScreenPlay"); mEventSink.success(getParams("onStartFullScreenPlay", null));
} }
@Override @Override
public void onStopFullScreenPlay() { public void onStopFullScreenPlay() {
mEventSink.success("onStopFullScreenPlay"); mEventSink.success(getParams("onStopFullScreenPlay", null));
} }
@Override @Override
...@@ -105,7 +108,7 @@ public class SuperPlatformPlayerView implements PlatformView, MethodChannel.Meth ...@@ -105,7 +108,7 @@ public class SuperPlatformPlayerView implements PlatformView, MethodChannel.Meth
@Override @Override
public void onClickSmallReturnBtn() { public void onClickSmallReturnBtn() {
mEventSink.success(getParams("onSuperPlayerBackAction", null));
} }
@Override @Override
...@@ -244,4 +247,22 @@ public class SuperPlatformPlayerView implements PlatformView, MethodChannel.Meth ...@@ -244,4 +247,22 @@ public class SuperPlatformPlayerView implements PlatformView, MethodChannel.Meth
public void setLoop(boolean b) { public void setLoop(boolean b) {
mSuperPlayerView.setLoop(b); mSuperPlayerView.setLoop(b);
} }
private Map<String, Object> getParams(String event, Bundle bundle) {
Map<String, Object> param = new HashMap();
if (!event.isEmpty()) {
param.put("event", event);
}
if (bundle != null && !bundle.isEmpty()) {
Set<String> keySet = bundle.keySet();
for (String key : keySet) {
Object val = bundle.get(key);
param.put(key, val);
}
}
return param;
}
} }
...@@ -115,23 +115,33 @@ class _TestSuperPlayerState extends State<TestSuperPlayer> { ...@@ -115,23 +115,33 @@ class _TestSuperPlayerState extends State<TestSuperPlayer> {
_playerController.setPlayConfig(_playerConfig); _playerController.setPlayConfig(_playerConfig);
_playerController.onPlayerEventBroadcast.listen((event) { _playerController.onPlayerEventBroadcast.listen((event) {
setState(() { setState(() {
if (event == SuperPlayerViewEvent.onStartFullScreenPlay) { String evtName = event["event"];
_isFullSceen = true; if (evtName == SuperPlayerViewEvent.onStartFullScreenPlay) {
AutoOrientation.landscapeAutoMode(); if (defaultTargetPlatform == TargetPlatform.android) {
_isFullSceen = true;
///关闭状态栏,与底部虚拟操作按钮 AutoOrientation.landscapeAutoMode();
SystemChrome.setEnabledSystemUIOverlays([]);
} else { ///关闭状态栏,与底部虚拟操作按钮
_isFullSceen = false; SystemChrome.setEnabledSystemUIOverlays([]);
}
/// 如果是全屏就切换竖屏 print("onStartFullScreenPlay");
AutoOrientation.portraitAutoMode(); } else if (evtName == SuperPlayerViewEvent.onStopFullScreenPlay){
if (defaultTargetPlatform == TargetPlatform.android) {
///显示状态栏,与底部虚拟操作按钮 _isFullSceen = false;
SystemChrome.setEnabledSystemUIOverlays(
[SystemUiOverlay.top, SystemUiOverlay.bottom]); /// 如果是全屏就切换竖屏
AutoOrientation.portraitAutoMode();
///显示状态栏,与底部虚拟操作按钮
SystemChrome.setEnabledSystemUIOverlays(
[SystemUiOverlay.top, SystemUiOverlay.bottom]);
}
print("onStopFullScreenPlay");
} else if (evtName == SuperPlayerViewEvent.onSuperPlayerBackAction) {
print("onSuperPlayerBackAction");
}
} }
}); );
}); });
_initPlayer.complete(true); _initPlayer.complete(true);
}, },
......
...@@ -286,40 +286,50 @@ ...@@ -286,40 +286,50 @@
/// 返回事件 /// 返回事件
- (void)superPlayerBackAction:(SuperPlayerView *)player - (void)superPlayerBackAction:(SuperPlayerView *)player
{ {
[_eventSink success:[self getParamsWithEvent:@"onSuperPlayerBackAction" withParams:@{}]];
} }
/// 全屏改变通知 /// 全屏改变通知
- (void)superPlayerFullScreenChanged:(SuperPlayerView *)player - (void)superPlayerFullScreenChanged:(SuperPlayerView *)player
{ {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (!player.isFullScreen) {
[_eventSink success:[self getParamsWithEvent:@"onStopFullScreenPlay" withParams:@{}]];
if (orientation == UIInterfaceOrientationPortrait) {
[_eventSink success:@"onStopFullScreenPlay"];
}else { }else {
[_eventSink success:@"onStartFullScreenPlay"]; [_eventSink success:[self getParamsWithEvent:@"onStartFullScreenPlay" withParams:@{}]];
} }
} }
/// 播放开始通知 /// 播放开始通知
- (void)superPlayerDidStart:(SuperPlayerView *)player; - (void)superPlayerDidStart:(SuperPlayerView *)player;
{ {
[_eventSink success:[self getParamsWithEvent:@"onSuperPlayerDidStart" withParams:@{}]];
} }
/// 播放结束通知 /// 播放结束通知
- (void)superPlayerDidEnd:(SuperPlayerView *)player - (void)superPlayerDidEnd:(SuperPlayerView *)player
{ {
[_eventSink success:[self getParamsWithEvent:@"onSuperPlayerDidEnd" withParams:@{}]];
} }
/// 播放错误通知 /// 播放错误通知
- (void)superPlayerError:(SuperPlayerView *)player errCode:(int)code errMessage:(NSString *)why; - (void)superPlayerError:(SuperPlayerView *)player errCode:(int)code errMessage:(NSString *)why;
{ {
[_eventSink success:[self getParamsWithEvent:@"onSuperPlayerError" withParams:@{
@"errCode":@(code),
@"errMessage":why
}]];
} }
// 需要通知到父view的事件在此添加 // 需要通知到父view的事件在此添加
- (NSDictionary *)getParamsWithEvent:(NSString *)evtName withParams:(NSDictionary *)params
{
NSMutableDictionary<NSString*,NSObject*> *dict = [NSMutableDictionary dictionaryWithObject:evtName forKey:@"event"];
if (params != nil && params.count != 0) {
[dict addEntriesFromDictionary:params];
}
return dict;
}
+ (UINavigationController *)currentNavigationController + (UINavigationController *)currentNavigationController
{ {
......
...@@ -4,9 +4,9 @@ part of SuperPlayer; ...@@ -4,9 +4,9 @@ part of SuperPlayer;
class SuperPlayerPlatformViewController { class SuperPlayerPlatformViewController {
MethodChannel _channel; MethodChannel _channel;
StreamSubscription _eventSubscription; StreamSubscription _eventSubscription;
final StreamController<String> _eventStreamController = final StreamController<Map<dynamic, dynamic>> _eventStreamController =
StreamController.broadcast(); StreamController.broadcast();
Stream<String> get onPlayerEventBroadcast => _eventStreamController.stream; Stream<Map<dynamic, dynamic>> get onPlayerEventBroadcast => _eventStreamController.stream;
SuperPlayerPlatformViewController.init(int id) { SuperPlayerPlatformViewController.init(int id) {
_channel = new MethodChannel('cloud.tencent.com/superPlayer/$id'); _channel = new MethodChannel('cloud.tencent.com/superPlayer/$id');
......
...@@ -53,8 +53,12 @@ enum TXPlayerEvent{ ...@@ -53,8 +53,12 @@ enum TXPlayerEvent{
} }
abstract class SuperPlayerViewEvent{ abstract class SuperPlayerViewEvent{
static const onStartFullScreenPlay = "onStartFullScreenPlay"; static const onStartFullScreenPlay = "onStartFullScreenPlay";//进入全屏播放
static const onStopFullScreenPlay = "onStopFullScreenPlay"; static const onStopFullScreenPlay = "onStopFullScreenPlay";//退出全屏播放
static const onSuperPlayerDidStart = "onSuperPlayerDidStart";//播放开始通知
static const onSuperPlayerDidEnd = "onSuperPlayerDidEnd";//播放结束通知
static const onSuperPlayerError = "onSuperPlayerError";//播放错误通知
static const onSuperPlayerBackAction = "onSuperPlayerBackAction";//返回事件
} }
class SuperPlayerUrl { class SuperPlayerUrl {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论