Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 79ff5357ac | |||
| 2989ffd911 | |||
| 0510aafead | |||
| f6feec3090 | |||
| b3a8d96787 | |||
| ebc59bc4cf | |||
| 565453fe9e | |||
| 3e44e0ebe7 | |||
| f255d10c94 | |||
| a8a160324e |
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.5</string>
|
||||
<string>2.6</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
Pod::Spec.new do |s|
|
||||
|
||||
s.name = "LFLiveKit"
|
||||
s.version = "2.5"
|
||||
s.version = "2.6"
|
||||
s.summary = "LaiFeng ios Live. LFLiveKit."
|
||||
s.homepage = "https://github.com/chenliming777"
|
||||
s.license = { :type => "MIT", :file => "LICENSE" }
|
||||
|
||||
@@ -98,7 +98,7 @@ NSString *const LFAudioComponentFailedToCreateNotification = @"LFAudioComponentF
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
dispatch_async(self.taskQueue, ^{
|
||||
dispatch_sync(self.taskQueue, ^{
|
||||
if (self.componetInstance) {
|
||||
self.isRunning = NO;
|
||||
AudioOutputUnitStop(self.componetInstance);
|
||||
@@ -121,7 +121,7 @@ NSString *const LFAudioComponentFailedToCreateNotification = @"LFAudioComponentF
|
||||
AudioOutputUnitStart(self.componetInstance);
|
||||
});
|
||||
} else {
|
||||
dispatch_async(self.taskQueue, ^{
|
||||
dispatch_sync(self.taskQueue, ^{
|
||||
self.isRunning = NO;
|
||||
NSLog(@"MicrophoneSource: stopRunning");
|
||||
AudioOutputUnitStop(self.componetInstance);
|
||||
@@ -182,7 +182,7 @@ NSString *const LFAudioComponentFailedToCreateNotification = @"LFAudioComponentF
|
||||
reason = [[[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey] integerValue];
|
||||
if (reason == AVAudioSessionInterruptionTypeBegan) {
|
||||
if (self.isRunning) {
|
||||
dispatch_async(self.taskQueue, ^{
|
||||
dispatch_sync(self.taskQueue, ^{
|
||||
NSLog(@"MicrophoneSource: stopRunning");
|
||||
AudioOutputUnitStop(self.componetInstance);
|
||||
});
|
||||
|
||||
@@ -110,6 +110,7 @@
|
||||
}
|
||||
|
||||
- (void)setCaptureDevicePosition:(AVCaptureDevicePosition)captureDevicePosition {
|
||||
if(captureDevicePosition == self.videoCamera.cameraPosition) return;
|
||||
[self.videoCamera rotateCamera];
|
||||
self.videoCamera.frameRate = (int32_t)_configuration.videoFrameRate;
|
||||
[self reloadMirror];
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
/// 音频码率
|
||||
/// 音频码率 (默认96Kbps)
|
||||
typedef NS_ENUM (NSUInteger, LFLiveAudioBitRate) {
|
||||
/// 32Kbps 音频码率
|
||||
LFLiveAudioBitRate_32Kbps = 32000,
|
||||
@@ -18,11 +18,11 @@ typedef NS_ENUM (NSUInteger, LFLiveAudioBitRate) {
|
||||
LFLiveAudioBitRate_96Kbps = 96000,
|
||||
/// 128Kbps 音频码率
|
||||
LFLiveAudioBitRate_128Kbps = 128000,
|
||||
/// 默认音频码率,默认为 64Kbps
|
||||
/// 默认音频码率,默认为 96Kbps
|
||||
LFLiveAudioBitRate_Default = LFLiveAudioBitRate_96Kbps
|
||||
};
|
||||
|
||||
/// 采样率 (默认44.1Hz)
|
||||
/// 音频采样率 (默认44.1KHz)
|
||||
typedef NS_ENUM (NSUInteger, LFLiveAudioSampleRate){
|
||||
/// 16KHz 采样率
|
||||
LFLiveAudioSampleRate_16000Hz = 16000,
|
||||
@@ -30,21 +30,21 @@ typedef NS_ENUM (NSUInteger, LFLiveAudioSampleRate){
|
||||
LFLiveAudioSampleRate_44100Hz = 44100,
|
||||
/// 48KHz 采样率
|
||||
LFLiveAudioSampleRate_48000Hz = 48000,
|
||||
/// 默认音频码率,默认为 64Kbps
|
||||
/// 默认音频采样率,默认为 44.1KHz
|
||||
LFLiveAudioSampleRate_Default = LFLiveAudioSampleRate_44100Hz
|
||||
};
|
||||
|
||||
/// Audio Live quality(音频质量)
|
||||
typedef NS_ENUM (NSUInteger, LFLiveAudioQuality){
|
||||
/// 高音频质量 audio sample rate: 16KHz audio bitrate: numberOfChannels 1 : 32Kbps 2 : 64Kbps
|
||||
/// 低音频质量 audio sample rate: 16KHz audio bitrate: numberOfChannels 1 : 32Kbps 2 : 64Kbps
|
||||
LFLiveAudioQuality_Low = 0,
|
||||
/// 高音频质量 audio sample rate: 44KHz audio bitrate: 96Kbps
|
||||
/// 中音频质量 audio sample rate: 44.1KHz audio bitrate: 96Kbps
|
||||
LFLiveAudioQuality_Medium = 1,
|
||||
/// 高音频质量 audio sample rate: 44MHz audio bitrate: 128Kbps
|
||||
/// 高音频质量 audio sample rate: 44.1MHz audio bitrate: 128Kbps
|
||||
LFLiveAudioQuality_High = 2,
|
||||
/// 高音频质量 audio sample rate: 48MHz, audio bitrate: 128Kbps
|
||||
/// 超高音频质量 audio sample rate: 48KHz, audio bitrate: 128Kbps
|
||||
LFLiveAudioQuality_VeryHigh = 3,
|
||||
/// 默认音频质量 audio sample rate: 44MHz, audio bitrate: 96Kbps
|
||||
/// 默认音频质量 audio sample rate: 44.1KHz, audio bitrate: 96Kbps
|
||||
LFLiveAudioQuality_Default = LFLiveAudioQuality_High
|
||||
};
|
||||
|
||||
@@ -63,7 +63,7 @@ typedef NS_ENUM (NSUInteger, LFLiveAudioQuality){
|
||||
@property (nonatomic, assign) NSUInteger numberOfChannels;
|
||||
/// 采样率
|
||||
@property (nonatomic, assign) LFLiveAudioSampleRate audioSampleRate;
|
||||
// 码率
|
||||
/// 码率
|
||||
@property (nonatomic, assign) LFLiveAudioBitRate audioBitrate;
|
||||
/// flv编码音频头 44100 为0x12 0x10
|
||||
@property (nonatomic, assign, readonly) char *asc;
|
||||
|
||||
@@ -10,5 +10,9 @@
|
||||
|
||||
@implementation LFLiveDebug
|
||||
|
||||
- (NSString *)description {
|
||||
return [NSString stringWithFormat:@"丢掉的帧数:%ld 总帧数:%ld 上次的音频捕获个数:%d 上次的视频捕获个数:%d 未发送个数:%ld 总流量:%0.f",_dropFrame,_totalFrame,_currentCapturedAudioCount,_currentCapturedVideoCount,_unSendCount,_dataFlow];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -62,9 +62,7 @@ static const NSUInteger defaultSendBufferMaxCount = 600;///< 最大缓冲区为6
|
||||
} else {
|
||||
///< 排序
|
||||
[self.sortList addObject:frame];
|
||||
NSArray *sortedSendQuery = [self.sortList sortedArrayUsingFunction:frameDataCompare context:NULL];
|
||||
[self.sortList removeAllObjects];
|
||||
[self.sortList addObjectsFromArray:sortedSendQuery];
|
||||
[self.sortList sortUsingFunction:frameDataCompare context:nil];
|
||||
/// 丢帧
|
||||
[self removeExpireFrame];
|
||||
/// 添加至缓冲区
|
||||
@@ -100,7 +98,7 @@ static const NSUInteger defaultSendBufferMaxCount = 600;///< 最大缓冲区为6
|
||||
|
||||
NSArray *iFrames = [self expireIFrames];///< 删除一个I帧(但一个I帧可能对应多个nal)
|
||||
self.lastDropFrames += [iFrames count];
|
||||
if (iFrames) {
|
||||
if (iFrames && iFrames.count > 0) {
|
||||
[self.list removeObjectsInArray:iFrames];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
LFLiveKit
|
||||
==============
|
||||

|
||||

|
||||
|
||||
|
||||
[](https://travis-ci.org/LaiFengiOS/LFLiveKit)
|
||||
@@ -134,6 +134,8 @@ func liveSession(session: LFLiveSession?, liveStateDidChange state: LFLiveState)
|
||||
* CHANGE: modify bugs,support ios7 live.
|
||||
* 2.2.4.3
|
||||
* CHANGE: modify bugs,support swift import.
|
||||
* 2.5
|
||||
* CHANGE: modify bugs,support bitcode.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
@@ -7,6 +7,7 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
5EA73C6322E98031301F2E03 /* Pods_LFLiveKitSwiftDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */; };
|
||||
84D8B48C1D757D4000752B56 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B48B1D757D4000752B56 /* AppDelegate.swift */; };
|
||||
84D8B48E1D757D4000752B56 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D8B48D1D757D4000752B56 /* ViewController.swift */; };
|
||||
84D8B4911D757D4000752B56 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B48F1D757D4000752B56 /* Main.storyboard */; };
|
||||
@@ -21,12 +22,11 @@
|
||||
84D8B4B21D757DBB00752B56 /* close_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4AA1D757DBB00752B56 /* close_preview@2x.png */; };
|
||||
84D8B4B31D757DBB00752B56 /* close_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4AB1D757DBB00752B56 /* close_preview@3x.png */; };
|
||||
84D8B4BD1D757E0E00752B56 /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */; };
|
||||
9CA0546A1BD4E74670872B9B /* libPods-LFLiveKitSwiftDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LFLiveKitSwiftDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
7265B07B4B6CEE8ECE8F7A63 /* Pods-LFLiveKitSwiftDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKitSwiftDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
843592751DD30BF000811FC7 /* LFLiveKitSwiftDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LFLiveKitSwiftDemo-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
84D8B4881D757D4000752B56 /* LFLiveKitSwiftDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LFLiveKitSwiftDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
84D8B48B1D757D4000752B56 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
84D8B48D1D757D4000752B56 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||
@@ -43,6 +43,7 @@
|
||||
84D8B4AA1D757DBB00752B56 /* close_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@2x.png"; sourceTree = "<group>"; };
|
||||
84D8B4AB1D757DBB00752B56 /* close_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@3x.png"; sourceTree = "<group>"; };
|
||||
84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; };
|
||||
A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LFLiveKitSwiftDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
DAC498DB742E949DED005ECE /* Pods-LFLiveKitSwiftDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKitSwiftDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo.release.xcconfig"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@@ -52,7 +53,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
84D8B4BD1D757E0E00752B56 /* libstdc++.tbd in Frameworks */,
|
||||
9CA0546A1BD4E74670872B9B /* libPods-LFLiveKitSwiftDemo.a in Frameworks */,
|
||||
5EA73C6322E98031301F2E03 /* Pods_LFLiveKitSwiftDemo.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -62,7 +63,7 @@
|
||||
23FA2B0543E0C2A8E7C84D9E /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */,
|
||||
A28643F373DE90D96602753C /* Pods_LFLiveKitSwiftDemo.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
@@ -91,6 +92,7 @@
|
||||
children = (
|
||||
84D8B48B1D757D4000752B56 /* AppDelegate.swift */,
|
||||
84D8B48D1D757D4000752B56 /* ViewController.swift */,
|
||||
843592751DD30BF000811FC7 /* LFLiveKitSwiftDemo-Bridging-Header.h */,
|
||||
84D8B48F1D757D4000752B56 /* Main.storyboard */,
|
||||
84D8B4A31D757DBB00752B56 /* images */,
|
||||
84D8B4921D757D4000752B56 /* Assets.xcassets */,
|
||||
@@ -320,7 +322,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
@@ -359,7 +361,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
VALIDATE_PRODUCT = YES;
|
||||
@@ -375,13 +377,13 @@
|
||||
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
|
||||
HEADER_SEARCH_PATHS = "$(inherited)";
|
||||
INFOPLIST_FILE = LFLiveKitSwiftDemo/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||
OTHER_LDFLAGS = "-all_load";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
@@ -395,13 +397,13 @@
|
||||
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
|
||||
HEADER_SEARCH_PATHS = "$(inherited)";
|
||||
INFOPLIST_FILE = LFLiveKitSwiftDemo/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||
OTHER_LDFLAGS = "-all_load";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "LFLiveKitSwiftDemo/LFLiveKitSwiftDemo-Bridging-Header.h";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>..</string>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>..</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// LFLiveKitSwiftDemo-Bridging-Header.h
|
||||
// LFLiveKitSwiftDemo
|
||||
//
|
||||
// Created by admin on 2016/11/9.
|
||||
// Copyright © 2016年 admin. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef LFLiveKitSwiftDemo_Bridging_Header_h
|
||||
#define LFLiveKitSwiftDemo_Bridging_Header_h
|
||||
|
||||
#import <LFLiveKit/LFLiveKit.h>
|
||||
|
||||
#endif /* LFLiveKitSwiftDemo_Bridging_Header_h */
|
||||
@@ -14,6 +14,10 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
|
||||
session.delegate = self
|
||||
session.preView = self.view
|
||||
|
||||
self.requestAccessForVideo()
|
||||
self.requestAccessForAudio()
|
||||
self.view.backgroundColor = UIColor.clear
|
||||
@@ -23,6 +27,10 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
|
||||
containerView.addSubview(beautyButton)
|
||||
containerView.addSubview(cameraButton)
|
||||
containerView.addSubview(startLiveButton)
|
||||
|
||||
cameraButton.addTarget(self, action: #selector(didTappedCameraButton(_:)), for:.touchUpInside)
|
||||
beautyButton.addTarget(self, action: #selector(didTappedBeautyButton(_:)), for: .touchUpInside)
|
||||
startLiveButton.addTarget(self, action: #selector(didTappedStartLiveButton(_:)), for: .touchUpInside)
|
||||
}
|
||||
|
||||
override func didReceiveMemoryWarning() {
|
||||
@@ -33,44 +41,45 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
|
||||
//MARK: AccessAuth
|
||||
|
||||
func requestAccessForVideo() -> Void {
|
||||
let status = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
|
||||
let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo);
|
||||
switch status {
|
||||
// 许可对话没有出现,发起授权许可
|
||||
case AVAuthorizationStatus.NotDetermined:
|
||||
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (granted) in
|
||||
if (granted) {
|
||||
dispatch_async(dispatch_get_main_queue(), {
|
||||
self.session.running = true;
|
||||
});
|
||||
case AVAuthorizationStatus.notDetermined:
|
||||
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted) in
|
||||
if(granted){
|
||||
DispatchQueue.main.async {
|
||||
self.session.running = true
|
||||
}
|
||||
}
|
||||
})
|
||||
break;
|
||||
// 已经开启授权,可继续
|
||||
case AVAuthorizationStatus.Authorized:
|
||||
case AVAuthorizationStatus.authorized:
|
||||
session.running = true;
|
||||
break;
|
||||
// 用户明确地拒绝授权,或者相机设备无法访问
|
||||
case AVAuthorizationStatus.Denied: break
|
||||
case AVAuthorizationStatus.Restricted:break;
|
||||
case AVAuthorizationStatus.denied: break
|
||||
case AVAuthorizationStatus.restricted:break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
func requestAccessForAudio() -> Void {
|
||||
let status = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeAudio)
|
||||
let status = AVCaptureDevice.authorizationStatus(forMediaType:AVMediaTypeAudio)
|
||||
switch status {
|
||||
// 许可对话没有出现,发起授权许可
|
||||
case AVAuthorizationStatus.NotDetermined:
|
||||
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeAudio, completionHandler: { (granted) in
|
||||
case AVAuthorizationStatus.notDetermined:
|
||||
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeAudio, completionHandler: { (granted) in
|
||||
|
||||
})
|
||||
break;
|
||||
// 已经开启授权,可继续
|
||||
case AVAuthorizationStatus.Authorized:
|
||||
case AVAuthorizationStatus.authorized:
|
||||
break;
|
||||
// 用户明确地拒绝授权,或者相机设备无法访问
|
||||
case AVAuthorizationStatus.Denied: break
|
||||
case AVAuthorizationStatus.Restricted:break;
|
||||
case AVAuthorizationStatus.denied: break
|
||||
case AVAuthorizationStatus.restricted:break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -90,21 +99,23 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
|
||||
func liveSession(_ session: LFLiveSession?, liveStateDidChange state: LFLiveState) {
|
||||
print("liveStateDidChange: \(state.rawValue)")
|
||||
switch state {
|
||||
case LFLiveState.Ready:
|
||||
case LFLiveState.ready:
|
||||
stateLabel.text = "未连接"
|
||||
break;
|
||||
case LFLiveState.Pending:
|
||||
case LFLiveState.pending:
|
||||
stateLabel.text = "连接中"
|
||||
break;
|
||||
case LFLiveState.Start:
|
||||
case LFLiveState.start:
|
||||
stateLabel.text = "已连接"
|
||||
break;
|
||||
case LFLiveState.Error:
|
||||
case LFLiveState.error:
|
||||
stateLabel.text = "连接错误"
|
||||
break;
|
||||
case LFLiveState.Stop:
|
||||
case LFLiveState.stop:
|
||||
stateLabel.text = "未连接"
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,13 +138,13 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
|
||||
// 美颜
|
||||
func didTappedBeautyButton(_ button: UIButton) -> Void {
|
||||
session.beautyFace = !session.beautyFace;
|
||||
beautyButton.selected = !session.beautyFace;
|
||||
beautyButton.isSelected = !session.beautyFace
|
||||
}
|
||||
|
||||
// 摄像头
|
||||
func didTappedCameraButton(_ button: UIButton) -> Void {
|
||||
let devicePositon = session.captureDevicePosition;
|
||||
session.captureDevicePosition = (devicePositon == AVCaptureDevicePosition.Back) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back;
|
||||
session.captureDevicePosition = (devicePositon == AVCaptureDevicePosition.back) ? AVCaptureDevicePosition.front : AVCaptureDevicePosition.back;
|
||||
}
|
||||
|
||||
// 关闭
|
||||
@@ -144,26 +155,23 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
|
||||
//MARK: - Getters and Setters
|
||||
|
||||
// 默认分辨率368 * 640 音频:44.1 iphone6以上48 双声道 方向竖屏
|
||||
lazy var session: LFLiveSession = {
|
||||
let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration()
|
||||
let videoConfiguration = LFLiveVideoConfiguration.defaultConfigurationForQuality(LFLiveVideoQuality.Low3)
|
||||
var session: LFLiveSession = {
|
||||
let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration(for: LFLiveAudioQuality.high)
|
||||
let videoConfiguration = LFLiveVideoConfiguration.defaultConfiguration(for: LFLiveVideoQuality.low3)
|
||||
let session = LFLiveSession(audioConfiguration: audioConfiguration, videoConfiguration: videoConfiguration)
|
||||
|
||||
session?.delegate = self
|
||||
session?.preView = self.view
|
||||
return session!
|
||||
}()
|
||||
|
||||
// 视图
|
||||
lazy var containerView: UIView = {
|
||||
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height))
|
||||
var containerView: UIView = {
|
||||
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
|
||||
containerView.backgroundColor = UIColor.clear
|
||||
containerView.autoresizingMask = [UIViewAutoresizing.flexibleHeight, UIViewAutoresizing.flexibleHeight]
|
||||
return containerView
|
||||
}()
|
||||
|
||||
// 状态Label
|
||||
lazy var stateLabel: UILabel = {
|
||||
var stateLabel: UILabel = {
|
||||
let stateLabel = UILabel(frame: CGRect(x: 20, y: 20, width: 80, height: 40))
|
||||
stateLabel.text = "未连接"
|
||||
stateLabel.textColor = UIColor.white
|
||||
@@ -172,49 +180,36 @@ class ViewController: UIViewController, LFLiveSessionDelegate {
|
||||
}()
|
||||
|
||||
// 关闭按钮
|
||||
lazy var closeButton: UIButton = {
|
||||
let closeButton = UIButton(frame: CGRect(x: self.view.frame.width - 10 - 44, y: 20, width: 44, height: 44))
|
||||
var closeButton: UIButton = {
|
||||
let closeButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 10 - 44, y: 20, width: 44, height: 44))
|
||||
closeButton.setImage(UIImage(named: "close_preview"), for: UIControlState())
|
||||
closeButton.addTarget(self, action: #selector(didTappedCloseButton(_:)), for: UIControlEvents.touchUpInside)
|
||||
return closeButton
|
||||
}()
|
||||
|
||||
// 摄像头
|
||||
lazy var cameraButton: UIButton = {
|
||||
let cameraButton = UIButton(frame: CGRect(x: self.view.frame.width - 54 * 2, y: 20, width: 44, height: 44))
|
||||
var cameraButton: UIButton = {
|
||||
let cameraButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 54 * 2, y: 20, width: 44, height: 44))
|
||||
cameraButton.setImage(UIImage(named: "camra_preview"), for: UIControlState())
|
||||
cameraButton.addTarget(self, action: #selector(didTappedCameraButton(_:)), for: UIControlEvents.touchUpInside)
|
||||
return cameraButton
|
||||
}()
|
||||
|
||||
// 摄像头
|
||||
lazy var beautyButton: UIButton = {
|
||||
let beautyButton = UIButton(frame: CGRect(x: self.view.frame.width - 54 * 3, y: 20, width: 44, height: 44))
|
||||
beautyButton.setImage(UIImage(named: "camra_preview"), for: UIControlState.selected)
|
||||
var beautyButton: UIButton = {
|
||||
let beautyButton = UIButton(frame: CGRect(x: UIScreen.main.bounds.width - 54 * 3, y: 20, width: 44, height: 44))
|
||||
beautyButton.setImage(UIImage(named: "camra_beauty"), for: UIControlState.selected)
|
||||
beautyButton.setImage(UIImage(named: "camra_beauty_close"), for: UIControlState())
|
||||
beautyButton.addTarget(self, action: #selector(didTappedBeautyButton(_:)), for: UIControlEvents.touchUpInside)
|
||||
return beautyButton
|
||||
}()
|
||||
|
||||
// 开始直播按钮
|
||||
lazy var startLiveButton: UIButton = {
|
||||
let startLiveButton = UIButton(frame: CGRect(x: 30, y: self.view.frame.height - 50, width: self.view.frame.width - 10 - 44, height: 44))
|
||||
var startLiveButton: UIButton = {
|
||||
let startLiveButton = UIButton(frame: CGRect(x: 30, y: UIScreen.main.bounds.height - 50, width: UIScreen.main.bounds.width - 10 - 44, height: 44))
|
||||
startLiveButton.layer.cornerRadius = 22
|
||||
startLiveButton.setTitleColor(UIColor.black, for:UIControlState())
|
||||
startLiveButton.setTitle("开始直播", for: UIControlState())
|
||||
startLiveButton.titleLabel!.font = UIFont.systemFont(ofSize: 14)
|
||||
startLiveButton.backgroundColor = UIColor(colorLiteralRed: 50, green: 32, blue: 245, alpha: 1)
|
||||
startLiveButton.addTarget(self, action: #selector(didTappedStartLiveButton(_:)), for: UIControlEvents.touchUpInside)
|
||||
return startLiveButton
|
||||
}()
|
||||
|
||||
// 转屏
|
||||
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
|
||||
return UIInterfaceOrientationMask.portrait
|
||||
}
|
||||
|
||||
override var shouldAutorotate : Bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
source 'https://github.com/CocoaPods/Specs.git'
|
||||
platform :ios,'7.0'
|
||||
|
||||
use_frameworks!
|
||||
|
||||
target “LFLiveKitSwiftDemo” do
|
||||
pod 'LFLiveKit', :path => '../../.'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user