提交 c57d1a66 authored 作者: zhiruiou's avatar zhiruiou

SuperPlayerView添加进入全屏,退出全屏,返回按钮通知

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