我正在尝试使用 ReplayKit
将录制功能添加到我的基于 C++ 的游戏中。我在我的游戏代码中检查 iOS 版本是否为 9.0 或更高版本,如果是,我将调用 RecordReplayIOS::startRecording()
然后 ReplayKit 应该开始录制。
出于某种原因,startRecordingWithMicrophoneEnabled
函数总是返回错误 -5803
,根据 API 文档,这意味着 RPRecordingErrorFailedToStart
。知道我做错了什么吗?
RecordReplayIOS.hpp
:
#ifndef __RECORD_REPLAY_IOS_HPP__
#define __RECORD_REPLAY_IOS_HPP__
class RecordReplayIOS {
public:
static bool canRecord();
static void startRecording();
static void stopRecording();
};
#endif
RecordReplayIOS.mm
:
#include "RecordReplay_ios.hpp"
#include "ReplayKit/ReplayKit.h"
@interface Recorder : NSObject
+(void)startRecording;
+(void)stopRecording;
@end
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
bool RecordReplayIOS::canRecord() {
// ReplayKit needs at least iOS 9
if (SYSTEM_VERSION_LESS_THAN(@"9.0")) {
return false;
}
return true;
}
void RecordReplayIOS::startRecording() {
[Recorder startRecording];
}
void RecordReplayIOS::stopRecording() {
[Recorder stopRecording];
}
@implementation Recorder
+(void)startRecording {
RPScreenRecorder* recorder = RPScreenRecorder.sharedRecorder;
recorder.delegate = self;
[recorder startRecordingWithMicrophoneEnabled:false handler:^(NSError * error) {
if(error != nil) {
NSString* desc = error.description;
return;
}
}];
}
+(void)stopRecording {
RPScreenRecorder* recorder = RPScreenRecorder.sharedRecorder;
[recorder stopRecordingWithHandler:^(RPPreviewViewController *previewViewController, NSError *error) {
if(error != nil) {
NSString* desc = error.description;
return;
}
if(previewViewController) {
//do stuff...
}
}];
}
@end
最佳答案
代码没有问题。看来我只是尝试将 ReplayKit 与太旧的 iPad 一起使用。显然 ReplayKit 需要 A7 或 A8 处理器。我的配备 A6 处理器的 iPad 4 根本无法使用 ReplayKit。
检查设备是否可以使用 ReplayKit 的正确方法是查询 RPScreenRecorder.sharedRecorder.available
。如果设备支持 ReplayKit,则返回 true。
关于c++ - ReplayKit 返回错误 "RPRecordingErrorFailedToStart",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33613763/