SenbayKit
SenbayKit 是一个开发库,用于向您的 iOS 应用程序添加 Senbay 功能。在这个库中,包括了三个核心库:Senbay 摄像头、播放器和阅读器。
要求
SenbayKit 需要 iOS10 或更高版本。此库支持 Swift 和 Objective-C。
示例
要运行示例项目,首先克隆仓库,然后从 Example 目录中运行 pod install
。
安装
SenbayKit 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中即可
pod 'SenbayKit', :git => 'https://github.com/tetujin/SenbayKit.git'
如何使用
设置
- 设置Info.plist 请将以下键添加到Info.plist中
- NSCameraUsageDescription
- NSMicrophoneUsageDescription
- NSPhotoLibraryUsageDescription
- NSLocationWhenInUseUsageDescription(仅限SenbayCamera)
- 将SenbayKit导入您的源代码
@import SenbayKit;
Senbay Camera
- 初始化SenbayCamera并设置预览视图
// Objective-C //
SenbayCamera * camera = [[SenbayCamera alloc] initWithPreviewView: UI_IMAGE_VIEW];
camera.delegate = self;
[camera activate];
// Swift //
var camera = SenbayCamera.init(previewView: UI_IMAGE_VIEW)
camera.delegate = self;
camera.activate()
- 固定UIViewController方向
SenbayCamera仅支持横屏。请将以下代码添加到您的UIViewController中,以固定UIViewController方向。
// Objective-C //
- (BOOL) shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeRight;
}
// Swift //
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
return .landscapeRight
}
- 开始和停止视频录制过程
录制的视频将自动保存到Photos.app中。
// Objective-C //
[camera startRecording];
[camera stopRecording];
// Swift //
camera.startRecording()
camera.stopRecording()
- 激活传感器
您可以在视频中嵌入传感器数据到动画二维码。请从SenbaySensorManager类激活所需的传感器。
// Objective-C //
// Accelerometer: ACCX,ACCY,ACCZ
[camera.sensorManager.imu activateAccelerometer];
// Gyroscope: PITC,ROLL,YAW
[camera.sensorManager.imu activateGyroscope];
// Magnetometer: MAGX,MAGY,MAGZ
[camera.sensorManager.imu activateMagnetometer];
// GPS: LONG,LATI,ALTI
[camera.sensorManager.location activateGPS];
// Compass: HEAD
[camera.sensorManager.location activateCompass];
// Barometer: AIRP
[camera.sensorManager.location activateBarometer];
// Speedometer: SPEE
[camera.sensorManager.location activateSpeedometer];
// Motion Activity: MACT
[camera.sensorManager.motionActivity activate];
// Battery: BATT
[camera.sensorManager.batteryLevel activate];
// Screen Brightness: BRIG
[camera.sensorManager.screenBrightness activate];
// Weather: TEMP,WEAT,HUMI,WIND
[camera.sensorManager.weather activate];
// HR: HTBT
[camera.sensorManager.ble activateHRM];
// BLE Tag: BTAG
[camera.sensorManager.ble activateBLETag];
// Network Socket: NTAG
[camera.sensorManager.networkSocket activateUdpScoketWithPort:5000];
// Swift //
// Accelerometer: ACCX,ACCY,ACCZ
if let imu = camera.sensorManager.imu{
imu.activateAccelerometer()
}
// GPS: LONG,LATI,ALTI
if let location = camera.sensorManager.location {
location.activateGPS()
}
// Weather: TEMP,WEAT,HUMI,WIND
if let weather = camera.sensorManager.weather{
weather.activate()
}
如果您想使用您自己的数据格式,请调用-useFreeFormatData:,并将数据设置到SenbaySensorManager。
// Objective-C //
[camera.sensorManager useFreeFormatData:YES];
[camera.sensorManager setFreeFormatData:@"YOUR DATA"];
// Swift //
camera.sensorManager.useFreeFormatData(true)
camera.sensorManager.setFreeFormatData("YOUR DATA")
- 在UIViewController中实现SenbayCameraDelegate
您可以通过实现SenbayCameraDelegate从SenbayCamera接收更新事件。
// Objective-C //
- (void) didUpdateFormattedRecordTime:(NSString *)recordTime;
- (void) didUpdateCurrentFPS:(int)currentFPS;
- (void) didUpdateQRCodeContent:(NSString *)qrcodeContent;
- (void) didUpdateVideoFrame:(UIImage *)videoFrame;
// Swift //
func didUpdateCurrentFPS(_ currentFPS: Int32)
func didUpdateFormattedRecordTime(_ recordTime: String!)
func didUpdateQRCodeContent(_ qrcodeContent: String!)
func didUpdateVideoFrame(_ videoFrame: UIImage!)
- (可选)通过RTMP直播SenbayVideo
RTMP(实时消息协议)是YouTube Live支持的流媒体协议之一。您可以通过以下代码使用以下代码通过RTMP流式传输SenbayVideo。
/// start a broadcast via YouTube Live (Please relace [xxxx-xxxx-xxxx-xxxx] to your stream name. You can get the name from https://www.youtube.com/live_dashboard )
[camera startBroadcastWithStreamName:@"[xxxx-xxxx-xxxx-xxxx]"
endpointURL:@"rtmp://username:[xxxx-xxxx-xxxx-xxxx]@a.rtmp.youtube.com/live2"];
/// stop the broadcast
[camera finishBroadcast];
/// start a broadcast
camera.startBroadcast(withStreamName:"[xxxx-xxxx-xxxx-xxxx]",
endpointURL:"rtmp://username:[xxxx-xxxx-xxxx-xxxx]@a.rtmp.youtube.com/live2")
/// stop the broadcast
camera.finishBroadcast()
- (可选)更改相机设置
您可以使用类`s`的`ubeCameraConfig`在实现`-activate`方法之前更改相机设置(例如,FPS、分辨率、视频导出)。
/// orverwride SenbayCameraConfig
SenbayCameraConfig * cameraConfig = [[SenbayCameraConfig alloc] initWithBuilderBlock:^(SenbayCameraConfig * _Nonnull config) {
config.maxFPS = 30;
config.videoSize = AVCaptureSessionPreset1280x720;
config.isDebug = YES;
}];
camera.config = cameraConfig;
/// or edit SenbayCameraConfig directly
camera.config.maxFPS = 60;
/// NOTE: The settings should be modified before activate the camera instance
[camera activate];
let config = SenbayCameraConfig.init { (config) in
config.isDebug = true
config.maxFPS = 30
config.videoSize = AVCaptureSession.Preset.hd1280x720
}
camera.config = cameraConfig;
/// or edit SenbayCameraConfig directly
camera.config.maxFPS = 60;
/// NOTE: The settings should be modified before activate the camera instance
camera.activate();
Senbay Player
- 在UIViewController中初始化SenbayPlayer
// Objective-C //
SenbayPlaer * player = [[SenbayPlayer alloc] initWithView:UI_VIEW];
player.delegate = self;
[player setupPlayerWithLoadedAsset: ASSET];
// Swift //
player = SenbayPlayer.init(view: playerView)
player.delegate = self;
player.setupPlayer(withLoadedAsset: ASSET)
- 播放和暂停SenbayPlayer
// Objective-C //
[player play];
[player pause];
// Swift //
player.play()
player.pause()
- 在UIViewController中实现SenbayPlayerDelegate
您可以通过实现该代理接收解码的传感器数据。
// Objective-C //
- (void)didDetectQRcode:(NSString *)qrcode;
- (void)didDecodeQRcode:(NSDictionary *)senbayData;
// Swift //
func didDetectQRcode(_ qrcode: String!)
func didDecodeQRcode(_ senbayData: [AnyHashable : Any]!)
Senbay Reader
- 在 UIViewController 中初始化 SenbayReader
// Objective-C //
SenbayReader * reader = [[SenbayReader alloc] init];
reader.delegate = self;
[reader startCameraReaderWithPreviewView: UI_VIEW];
// Swift //
var reader = SenbayReader()
reader.delegate = self;
reader.startCameraReader(withPreviewView: UI_VIEW)
- 通过 SenbayReaderDelegate 接收检测和解码的数据
// Objective-C //
- (void)didDetectQRcode:(NSString *)qrcode;
- (void)didDecodeQRcode:(NSDictionary *)senbayDat;
// Swift //
func didDetectQRcode(_ qrcode: String!)
func didDecodeQRcode(_ senbayData: [AnyHashable : Any]!)
作者和贡献者
SenbayKit 由 Yuuki Nishiyama 创作。此外,Takuro Yonezawa,Denzil Ferreira,Anind K. Dey,Jin Nakazawa 对此项目做出了巨大的贡献。请查看我们网站上的更多详细信息:http://www.senbay.info。
相关链接
引用
如果这些论文有助于你的研究,请在其出版物中进行引用
@inproceedings{Nishiyama:2018:SPI:3236112.3236154,
author = {Nishiyama, Yuuki and Dey, Anind K. and Ferreira, Denzil and Yonezawa, Takuro and Nakazawa, Jin},
title = {Senbay: A Platform for Instantly Capturing, Integrating, and Restreaming of Synchronized Multiple Sensor-data Stream},
booktitle = {Proceedings of the 20th International Conference on Human-Computer Interaction with Mobile Devices and Services Adjunct},
series = {MobileHCI '18},
year = {2018},
location = {Barcelona, Spain},
publisher = {ACM},
}
许可协议
SenbayKit 在 Apache License, Version 2.0 许可证下可用。更多信息请参阅 LICENSE 文件。