菜鸟教程小白 发表于 2022-12-11 18:51:41

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 &#39;https://github.com/CocoaPods/Specs&#39;
source &#39;https://github.com/twilio/cocoapod-specs&#39;

target &#39;MyApp&#39; do
# Uncomment the next line if you&#39;re using Swift or would like to use dynamic frameworks
# use_frameworks!

# Pods for MyApp
    pod &#39;TwilioVideo&#39;, &#39;1.0.0-beta5&#39;
    pod &#39;PureLayout&#39;, &#39;~&gt; 3.0&#39;
target &#39;MapleNativeProviderTests&#39; 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 &#34;TWVideoModule.h&#34;

static NSString* roomDidConnect               = @&#34;roomDidConnect&#34;;
static NSString* roomDidDisconnect            = @&#34;roomDidDisconnect&#34;;
static NSString* roomDidFailToConnect         = @&#34;roomDidFailToConnect&#34;;
static NSString* roomParticipantDidConnect    = @&#34;roomParticipantDidConnect&#34;;
static NSString* roomParticipantDidDisconnect = @&#34;roomParticipantDidDisconnect&#34;;

static NSString* participantAddedVideoTrack   = @&#34;participantAddedVideoTrack&#34;;
static NSString* participantRemovedVideoTrack = @&#34;participantRemovedVideoTrack&#34;;
static NSString* participantAddedAudioTrack   = @&#34;participantAddedAudioTrack&#34;;
static NSString* participantRemovedAudioTrack = @&#34;participantRemovedAudioTrack&#34;;
static NSString* participantEnabledTrack      = @&#34;participantEnabledTrack&#34;;
static NSString* participantDisabledTrack   = @&#34;participantDisabledTrack&#34;;

static NSString* cameraDidStart               = @&#34;cameraDidStart&#34;;
static NSString* cameraWasInterrupted         = @&#34;cameraWasInterrupted&#34;;
static NSString* cameraDidStopRunning         = @&#34;cameraDidStopRunning&#34;;

@interface TWVideoModule () &lt;TVIParticipantDelegate, TVIRoomDelegate, TVIVideoTrackDelegate, TVICameraCapturerDelegate&gt;

@end

@implementation TWVideoModule

@synthesize bridge = _bridge;

RCT_EXPORT_MODULE();

- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}

- (NSArray&lt;NSString *&gt; *)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(@&#34;Camera %@&#34;, self.camera);

self.camera.delegate = self;

self.localVideoTrack = [self.localMedia addVideoTrack:YES
                                             capturer:self.camera
                                          constraints:
                                                error:nil];

self.localAudioTrack = ;

if (!self.localVideoTrack) {
    NSLog(@&#34;Failed to add video track&#34;);
} 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 &#39;react&#39;
import {
    NativeModules,
    NativeEventEmitter
} from &#39;react-native&#39;;

import {
    View,
} from &#39;native-base&#39;;

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 =&gt; e.remove());
      this._subscriptions = []
    }

    _registerEvents() {

      this._subscriptions = [

            this._eventEmitter.addListener(&#39;roomDidConnect&#39;, (data) =&gt; {
                if (this.props.onRoomDidConnect) {
                  this.props.onRoomDidConnect(data)
                }
            }),

            this._eventEmitter.addListener(&#39;roomDidDisconnect&#39;, (data) =&gt; {
                if (this.props.onRoomDidDisconnect) {
                  this.props.onRoomDidDisconnect(data)
                }
            }),

            this._eventEmitter.addListener(&#39;roomDidFailToConnect&#39;, (data) =&gt; {
                if (this.props.onRoomDidFailToConnect) {
                  this.props.onRoomDidFailToConnect(data)
                }
            }),

            this._eventEmitter.addListener(&#39;roomParticipantDidConnect&#39;, (data) =&gt; {
                if (this.props.onRoomParticipantDidConnect) {
                  this.props.onRoomParticipantDidConnect(data)
                }
            }),

            this._eventEmitter.addListener(&#39;roomParticipantDidDisconnect&#39;, (data) =&gt; {
                if (this.props.onRoomParticipantDidDisconnect) {
                  this.props.onRoomParticipantDidDisconnect(data)
                }
            }),

            this._eventEmitter.addListener(&#39;participantAddedVideoTrack&#39;, (data) =&gt; {
                if (this.props.onParticipantAddedVideoTrack) {
                  this.props.onParticipantAddedVideoTrack(data)
                }
            }),

            this._eventEmitter.addListener(&#39;participantRemovedVideoTrack&#39;, (data) =&gt; {
                if (this.props.onParticipantRemovedVideoTrack) {
                  this.props.onParticipantRemovedVideoTrack(data)
                }
            }),

            this._eventEmitter.addListener(&#39;participantAddedAudioTrack&#39;, (data) =&gt; {
                if (this.props.onParticipantAddedAudioTrack) {
                  this.props.onParticipantAddedAudioTrack(data)
                }
            }),

            this._eventEmitter.addListener(&#39;participantRemovedAudioTrack&#39;, (data) =&gt; {
                if (this.props.onParticipantRemovedAudioTrack) {
                  this.props.onParticipantRemovedAudioTrack(data)
                }
            }),

            this._eventEmitter.addListener(&#39;participantEnabledTrack&#39;, (data) =&gt; {
                if (this.props.onParticipantEnabledTrack) {
                  this.props.onParticipantEnabledTrack(data)
                }
            }),

            this._eventEmitter.addListener(&#39;participantDisabledTrack&#39;, (data) =&gt; {
                if (this.props.onParticipantDisabledTrack) {
                  this.props.onParticipantDisabledTrack(data)
                }
            }),

            this._eventEmitter.addListener(&#39;cameraDidStart&#39;, (data) =&gt; {
                if (this.props.onCameraDidStart) {
                  this.props.onCameraDidStart(data)
                }
            }),

            this._eventEmitter.addListener(&#39;cameraWasInterrupted&#39;, (data) =&gt; {
                if (this.props.onCameraWasInterrupted) {
                  this.props.onCameraWasInterrupted(data)
                }
            }),

            this._eventEmitter.addListener(&#39;cameraDidStopRunning&#39;, (data) =&gt; {
                if (this.props.onCameraDidStopRunning) {
                  this.props.onCameraDidStopRunning(data)
                }
            })

      ]

    }

    componentWillMount() {
      this._eventEmitter.addListener(&#39;cameraDidStart&#39;, (data) =&gt; {
            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]
查看完整版本: ios - 未向 TwilioVideo iOS SDK 的 TVIVideoCapturer 提供捕获器(iPhone 摄像头)