SenbayKit is a development library for adding Senbay functions to your iOS app. In this library, three core libraries are included: Senbay Camera, Player, and Reader.
SenbayKit requires iOS10 or later. This library supports both Swift and Objective-C.
To run the example project, clone the repo, and run pod install
from the Example directory first.
SenbayKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SenbayKit', :git => 'https://github.com/tetujin/SenbayKit.git'
- Setup Info.plist Please add following keys to Info.plist
- NSCameraUsageDescription
- NSMicrophoneUsageDescription
- NSPhotoLibraryUsageDescription
- NSLocationWhenInUseUsageDescription (only for SenbayCamera)
- Import SenbayKit into your source code
@import SenbayKit;
- Initialize SenbayCamera and set a preview view
// 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()
- Fix a UIViewController orientation
SenbayCamera supports only LandscapeRigth. Please add following code to your UIViewController for fixing the UIViewController.
// Objective-C //
- (BOOL) shouldAutorotate {
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeRight;
}
// Swift //
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
return .landscapeRight
}
- Start and stop a video recording process
The recorded video is saved into Photos.app automatically.
// Objective-C //
[camera startRecording];
[camera stopRecording];
// Swift //
camera.startRecording()
camera.stopRecording()
- Activate sensors
You can embedded sensor data into an animated QR code on a video. Please activate required sensors from SenbaySensorManager class.
// 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()
}
If you want to use your original data format, please call -useFreeFormatData:, and set your data to the SenbaySensorManager.
// Objective-C //
[camera.sensorManager useFreeFormatData:YES];
[camera.sensorManager setFreeFormatData:@"YOUR DATA"];
// Swift //
camera.sensorManager.useFreeFormatData(true)
camera.sensorManager.setFreeFormatData("YOUR DATA")
- Implement SenbayCameraDelegate on UIViewController
You can receive update events from SenbayCamera via SenbayCameraDelegate.
// 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!)
- (Option) Live Stream SenbayVideo via RTMP
RTMP (Real-Time Messaging Protocol) is one of a video, audio, and data streaming protocoal which is suppored on YouTube Live. You can stream SenbayVideo via RTMP by the following code.
/// 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()
- (Option) Change camera settings
You can cahnge camera settings (e.g., FPS, resolution, video export) using SenbayCameraConfig
class on SenbayCamera
before execute -activate
method.
/// 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();
- Initialize SenbayPlayer on UIViewController
// 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)
- Play and pause the SenbayPlayer
// Objective-C //
[player play];
[player pause];
// Swift //
player.play()
player.pause()
- Implement SenbayPlayerDelegate on UIViewController
You can receive the decoded sensor data by implementing the delegate.
// Objective-C //
- (void)didDetectQRcode:(NSString *)qrcode;
- (void)didDecodeQRcode:(NSDictionary *)senbayData;
// Swift //
func didDetectQRcode(_ qrcode: String!)
func didDecodeQRcode(_ senbayData: [AnyHashable : Any]!)
- Initialize SenbayReader on UIViewController
// 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)
- Receive detected and decoded data via SenbayReaderDelegate
// Objective-C //
- (void)didDetectQRcode:(NSString *)qrcode;
- (void)didDecodeQRcode:(NSDictionary *)senbayDat;
// Swift //
func didDetectQRcode(_ qrcode: String!)
func didDecodeQRcode(_ senbayData: [AnyHashable : Any]!)
SenbayKit is authord by Yuuki Nishiyama. In addition, Takuro Yonezawa, Denzil Ferreira, Anind K. Dey, Jin Nakazawa are deeply contributing this project. Please see more detail information on our website.
Please cite these papers in your publications if it helps your research:
@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 is available under the Apache License, Version 2.0 license. See the LICENSE file for more info.