如何让迷你控制器出现在 iOS 的 react-native-google-cast 中?

如何解决如何让迷你控制器出现在 iOS 的 react-native-google-cast 中?

我在启用了扩展控件的 React Native 应用程序中设置了 react-native-google-cast。文档暗示(herehere)迷你控制器应该自动出现。包中只有一个组件:CastButton。我在 AppDelegte.m 中启用了 useDefaultExpandedMediaControls,并且在投射开始时会出现扩展的控件。取消展开的控件后,将不会出现迷你控制器。

更新:尚未实施

关注this issue on Google Cast Github

一个好心的撒玛利亚人已经发布了 reimplementing in Typescript方法

我将把这段代码在这里以帮助其他人开始...

代码

package.json:

{
  "name": "iosvideo","version": "0.0.1","private": true,"scripts": {
    "android": "react-native run-android","ios": "react-native run-ios","start": "react-native start","test": "jest","lint": "eslint ."
  },"dependencies": {
    "react": "17.0.1","react-dom": "^17.0.2","react-native": "0.64.1","react-native-base64": "^0.2.1","react-native-google-cast": "^4.0.3","react-native-web": "^0.16.2"
  },"devDependencies": {
    "@babel/core": "^7.12.9","@babel/runtime": "^7.12.5","@react-native-community/eslint-config": "^2.0.0","babel-jest": "^26.6.3","babel-plugin-react-native-web": "^0.16.2","eslint": "7.14.0","jest": "^26.6.3","metro-react-native-babel-preset": "^0.64.0","react-test-renderer": "17.0.1"
  },"jest": {
    "preset": "react-native"
  }
}

App.js:

注意:我使用 HLS-Proxy 来处理 HLS CORS。

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow strict-local
 */

import React from 'react';
import {
  SafeAreaView,StatusBar,} from 'react-native';

import base64 from 'react-native-base64';

import GoogleCast,{ CastButton,useRemoteMediaClient } from 'react-native-google-cast';

const App = () => {

  const client = useRemoteMediaClient();

  const getProxyUrl = function(url) {

    const proxy_url = 'http://192.168.2.220:10000';
    const video_url = base64.encode(url);
    const file_extension = '.m3u8';
    const hls_proxy_url = `${proxy_url}/${video_url}${file_extension}`;

    return hls_proxy_url;

  };

  if (client) {
    client.loadMedia({
      mediaInfo: {
        contentUrl:
          getProxyUrl('http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl'),contentType: 'video/m3u',Metadata: {
          title: 'Apple Event',type: 'generic',},streamDuration: 0,startTime: 10,// seconds
    });
    GoogleCast.showExpandedControls();
  }

  return (
    <>
      <SafeAreaView>
        <StatusBar/>
        <CastButton style={{width: 24,height: 24,tintColor: 'black',alignSelf: 'flex-end',marginHorizontal: 8}} />
      </SafeAreaView>
    </>
  );
};

export default App;

AppDelegate.m:

#import "AppDelegate.h"

...

#import <GoogleCast/GoogleCast.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#ifdef FB_SONARKIT_ENABLED
  Initializeflipper(application);
#endif

  // https://github.com/facebook/react-native/issues/16376#issuecomment-810094592

  NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.js" fallbackResource:nil];

  RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation
                                              moduleProvider:nil
                                               launchOptions:launchOptions];
  #if RCT_DEV
   [bridge moduleForClass:[RCTDevLoadingView class]];
  #endif

  // END

  // RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"iosVideo"
                                            initialProperties:nil];

  if (@available(iOS 13.0,*)) {
      rootView.backgroundColor = [UIColor systemBackgroundColor];
  } else {
      rootView.backgroundColor = [UIColor whiteColor];
  }

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

  Nsstring *receiverappid = @"XXXXXXX";

  GCKdiscoveryCriteria *criteria = [[GCKdiscoveryCriteria alloc] initWithApplicationID:receiverappid];
  GCKCastOptions* options = [[GCKCastOptions alloc] initWithdiscoveryCriteria:criteria];
  [GCKCastContext setSharedInstanceWithOptions:options];
  [GCKCastContext sharedInstance].useDefaultExpandedMediaControls = true;

  return YES;
}

...

Google Cast SDK docs 声明

在CAF中,框架提供了一个控制栏, GCKUIMiniMediaControlsViewController,您可以将其添加到场景中 您想要显示持久控件的位置。有两种方法可以 将迷你控制器添加到发件人应用:

让 Cast 框架通过 用 GCKUICastContainerViewController 并添加一个 GCKUIMiniMediaControlsViewController 在其视图底部

将迷你控制器直接添加到现有的视图控制器中 使用 -[createMiniMediaControlsViewController] 创建一个 GCKUIMiniMediaControlsViewController 实例,然后将其添加到 容器视图控制器作为子视图。

我认为这是在 React Native 库中实现的,但也许我错过了一个步骤?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?