ios - 未向 TwilioVideo iOS SDK 的 TVIVideoCapturer 提供捕获器(iPhone 摄像头)
<p><p>我收到一个错误,我的 TwilioVideo 模块需要 Capturer(相机或麦克风),但没有接收到该输入。这个错误是在我们切换到 Cocoapods 来安装 SDK 和 PureLayout UI 库之后开始发生的。以前我们手动将所有这些依赖项安装到 XCode 中。</p>
<p>我正在开发 React Native iOS 0.40.0 版本,react-native-cli 版本为 1.0.0。我正在使用 XCode 版本 8.2.1 (8C1002),iPhone 6 模拟器在 iOS 10.2 上运行。我正在使用 Cocoapods 版本 1.2.0。我正在使用 TwilioVideo SDK 版本 1.0.0-beta5。还有一个 1.0.0-beta6 版本,我也尝试过(结果相同)。恢复到 1.0.0-beta4 版本确实消除了错误,这表明我实现注册音频和视频轨道的方式存在问题。</p>
<p>这是我的 Podfile:</p>
<pre><code>source 'https://github.com/CocoaPods/Specs'
source 'https://github.com/twilio/cocoapod-specs'
target 'MyApp' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for MyApp
pod 'TwilioVideo', '1.0.0-beta5'
pod 'PureLayout', '~> 3.0'
target 'MapleNativeProviderTests' do
inherit! :search_paths
# Pods for testing
end
end
</code></pre>
<p>我已经基于这个存储库在 XCode 中实现了一个 TwilioVideo 模块:<a href="https://github.com/gaston23/react-native-twilio-video-webrtc" rel="noreferrer noopener nofollow">react-native-twilio-video-webrtc</a> .他最近更新了存储库以适用于 React Native 0.40.0,这改变了 XCode 的导入语法。我已经尝试了旧的导入语法和新的导入语法,当我尝试挂载我的视频组件时,我继续收到以下错误:</p>
<p> <a href="/image/3CxLO.png" rel="noreferrer noopener nofollow"><img src="/image/3CxLO.png" alt="enter image description here"/></a> </p>
<p>这里是 <a href="https://media.twiliocdn.com/sdk/ios/video/releases/1.0.0-beta6/docs/" rel="noreferrer noopener nofollow">TwilioVideo SDK</a> 的文档.这是<a href="https://media.twiliocdn.com/sdk/ios/video/releases/1.0.0-beta6/docs/Protocols/TVIVideoCapturer.html" rel="noreferrer noopener nofollow">TVIVideoCapturer</a> .</p>
<p>我对 react-native-twilio-video-webrtc 进行了修改,它本质上只是 TwilioVideo SDK 的一个瘦包装器,使用 <code>RCT_EXPORT_METHOD</code> 来公开关键 API 方法。该库在 init 方法中初始化音频和视频轨道,这会导致一些烦人的行为与事件监听器在应用程序启动时未收到回调有关。因此,我将这些音轨移到了一个自定义的、公开的 <code>RCT_EXPORT_METHOD</code>,名为 <code>initialize</code>。这是我从应用程序中的特定 View 调用的,它安装视频并初始化相机/麦克风输入。</p>
<p>我对<code>TWVideoModule.m</code>的实现是:</p>
<pre><code>#import "TWVideoModule.h"
static NSString* roomDidConnect = @"roomDidConnect";
static NSString* roomDidDisconnect = @"roomDidDisconnect";
static NSString* roomDidFailToConnect = @"roomDidFailToConnect";
static NSString* roomParticipantDidConnect = @"roomParticipantDidConnect";
static NSString* roomParticipantDidDisconnect = @"roomParticipantDidDisconnect";
static NSString* participantAddedVideoTrack = @"participantAddedVideoTrack";
static NSString* participantRemovedVideoTrack = @"participantRemovedVideoTrack";
static NSString* participantAddedAudioTrack = @"participantAddedAudioTrack";
static NSString* participantRemovedAudioTrack = @"participantRemovedAudioTrack";
static NSString* participantEnabledTrack = @"participantEnabledTrack";
static NSString* participantDisabledTrack = @"participantDisabledTrack";
static NSString* cameraDidStart = @"cameraDidStart";
static NSString* cameraWasInterrupted = @"cameraWasInterrupted";
static NSString* cameraDidStopRunning = @"cameraDidStopRunning";
@interface TWVideoModule () <TVIParticipantDelegate, TVIRoomDelegate, TVIVideoTrackDelegate, TVICameraCapturerDelegate>
@end
@implementation TWVideoModule
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE();
- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}
- (NSArray<NSString *> *)supportedEvents
{
return @[roomDidConnect,
roomDidDisconnect,
roomDidFailToConnect,
roomParticipantDidConnect,
roomParticipantDidDisconnect,
participantAddedVideoTrack,
participantRemovedVideoTrack,
participantAddedAudioTrack,
participantRemovedAudioTrack,
participantEnabledTrack,
participantDisabledTrack,
cameraDidStopRunning,
cameraDidStart,
cameraWasInterrupted];
}
- (instancetype)init
{
self = ;
if (self) {
UIView* remoteMediaView = [ init];
//remoteMediaView.backgroundColor = ;
//remoteMediaView.translatesAutoresizingMaskIntoConstraints = NO;
self.remoteMediaView = remoteMediaView;
UIView* previewView = [ init];
//previewView.backgroundColor = ;
//previewView.translatesAutoresizingMaskIntoConstraints = NO;
self.previewView = previewView;
}
return self;
}
- (void)dealloc
{
;
self.remoteMediaView = nil;
;
self.previewView = nil;
self.participant = nil;
self.localMedia = nil;
self.camera = nil;
self.localVideoTrack = nil;
self.videoClient = nil;
self.room = nil;
}
RCT_EXPORT_METHOD(initialize) {
self.localMedia = [ init];
self.camera = [ init];
NSLog(@"Camera %@", self.camera);
self.camera.delegate = self;
self.localVideoTrack = [self.localMedia addVideoTrack:YES
capturer:self.camera
constraints:
error:nil];
self.localAudioTrack = ;
if (!self.localVideoTrack) {
NSLog(@"Failed to add video track");
} else {
// Attach view to video track for local preview
;
}
}
</code></pre>
<p>此文件的其余部分与添加和删除轨道以及加入/断开 Twiliochannel 有关,因此我没有包含它。我还有 <code>TWVideoPreviewManager</code> 和 <code>TWRemotePreviewManager</code>,它们只是为本地和远程视频流的媒体对象提供 UIView。</p>
<p>我的 <code>TwilioVideoComponent.js</code> 组件是:</p>
<pre><code>import React, { Component, PropTypes } from 'react'
import {
NativeModules,
NativeEventEmitter
} from 'react-native';
import {
View,
} from 'native-base';
const {TWVideoModule} = NativeModules;
class TwilioVideoComponent extends Component {
state = {};
static propTypes = {
onRoomDidConnect: PropTypes.func,
onRoomDidDisconnect: PropTypes.func,
onRoomDidFailToConnect: PropTypes.func,
onRoomParticipantDidConnect: PropTypes.func,
onRoomParticipantDidDisconnect: PropTypes.func,
onParticipantAddedVideoTrack: PropTypes.func,
onParticipantRemovedVideoTrack: PropTypes.func,
onParticipantAddedAudioTrack: PropTypes.func,
onParticipantRemovedAudioTrack: PropTypes.func,
onParticipantEnabledTrack: PropTypes.func,
onParticipantDisabledTrack: PropTypes.func,
onCameraDidStart: PropTypes.func,
onCameraWasInterrupted: PropTypes.func,
onCameraDidStopRunning: PropTypes.func,
...View.propTypes,
};
_subscriptions = [];
constructor(props) {
super(props);
this.flipCamera = this.flipCamera.bind(this);
this.startCall = this.startCall.bind(this);
this.endCall = this.endCall.bind(this);
this._eventEmitter = new NativeEventEmitter(TWVideoModule)
}
//
// Methods
/**
* Initializes camera and microphone tracks
*/
initializeVideo() {
TWVideoModule.initialize();
}
flipCamera() {
TWVideoModule.flipCamera();
}
startCall({roomName, accessToken}) {
TWVideoModule.startCallWithAccessToken(accessToken, roomName);
}
endCall() {
TWVideoModule.disconnect();
}
toggleVideo() {
TWVideoModule.toggleVideo();
}
toggleAudio() {
TWVideoModule.toggleAudio();
}
_unregisterEvents() {
this._subscriptions.forEach(e => e.remove());
this._subscriptions = []
}
_registerEvents() {
this._subscriptions = [
this._eventEmitter.addListener('roomDidConnect', (data) => {
if (this.props.onRoomDidConnect) {
this.props.onRoomDidConnect(data)
}
}),
this._eventEmitter.addListener('roomDidDisconnect', (data) => {
if (this.props.onRoomDidDisconnect) {
this.props.onRoomDidDisconnect(data)
}
}),
this._eventEmitter.addListener('roomDidFailToConnect', (data) => {
if (this.props.onRoomDidFailToConnect) {
this.props.onRoomDidFailToConnect(data)
}
}),
this._eventEmitter.addListener('roomParticipantDidConnect', (data) => {
if (this.props.onRoomParticipantDidConnect) {
this.props.onRoomParticipantDidConnect(data)
}
}),
this._eventEmitter.addListener('roomParticipantDidDisconnect', (data) => {
if (this.props.onRoomParticipantDidDisconnect) {
this.props.onRoomParticipantDidDisconnect(data)
}
}),
this._eventEmitter.addListener('participantAddedVideoTrack', (data) => {
if (this.props.onParticipantAddedVideoTrack) {
this.props.onParticipantAddedVideoTrack(data)
}
}),
this._eventEmitter.addListener('participantRemovedVideoTrack', (data) => {
if (this.props.onParticipantRemovedVideoTrack) {
this.props.onParticipantRemovedVideoTrack(data)
}
}),
this._eventEmitter.addListener('participantAddedAudioTrack', (data) => {
if (this.props.onParticipantAddedAudioTrack) {
this.props.onParticipantAddedAudioTrack(data)
}
}),
this._eventEmitter.addListener('participantRemovedAudioTrack', (data) => {
if (this.props.onParticipantRemovedAudioTrack) {
this.props.onParticipantRemovedAudioTrack(data)
}
}),
this._eventEmitter.addListener('participantEnabledTrack', (data) => {
if (this.props.onParticipantEnabledTrack) {
this.props.onParticipantEnabledTrack(data)
}
}),
this._eventEmitter.addListener('participantDisabledTrack', (data) => {
if (this.props.onParticipantDisabledTrack) {
this.props.onParticipantDisabledTrack(data)
}
}),
this._eventEmitter.addListener('cameraDidStart', (data) => {
if (this.props.onCameraDidStart) {
this.props.onCameraDidStart(data)
}
}),
this._eventEmitter.addListener('cameraWasInterrupted', (data) => {
if (this.props.onCameraWasInterrupted) {
this.props.onCameraWasInterrupted(data)
}
}),
this._eventEmitter.addListener('cameraDidStopRunning', (data) => {
if (this.props.onCameraDidStopRunning) {
this.props.onCameraDidStopRunning(data)
}
})
]
}
componentWillMount() {
this._eventEmitter.addListener('cameraDidStart', (data) => {
if (this.props.onCameraDidStart) {
this.props.onCameraDidStart(data)
}
});
this._registerEvents()
}
componentWillUnmount() {
this._unregisterEvents()
}
render() {
return this.props.children || null
}
}
export default TwilioVideoComponent;
</code></pre>
<p>我不确定如何修改 XCode 以兼容 TwilioVideo beta5 API。任何帮助将不胜感激。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在您的 podfile 中,查找 <code>#use_frameworks!</code> 并删除 #。</p></p>
<p style="font-size: 20px;">关于ios - 未向 TwilioVideo iOS SDK 的 TVIVideoCapturer 提供捕获器(iPhone 摄像头),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42075289/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42075289/
</a>
</p>
页:
[1]