dont export by default in the library.

allow this happen in the application level.
This commit is contained in:
Pavlos Vinieratos 2017-07-31 12:56:27 +02:00
parent 80539cd85d
commit 0884690f11
3 changed files with 29 additions and 17 deletions

View File

@ -2,9 +2,28 @@ import HaishinKit
import UIKit import UIKit
import XCGLogger import XCGLogger
import AVFoundation import AVFoundation
import Photos
let sampleRate:Double = 44_100 let sampleRate:Double = 44_100
class ExampleRecorderDelegate: DefaultAVMixerRecorderDelegate {
override func didFinishWriting(_ recorder: AVMixerRecorder) {
#if os(iOS)
guard let writer:AVAssetWriter = recorder.writer, shouldSaveToPhotoLibrary
else { return }
PHPhotoLibrary.shared().performChanges({() -> Void in
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: writer.outputURL)
}, completionHandler: { (isSuccess, error) -> Void in
do {
try FileManager.default.removeItem(at: writer.outputURL)
} catch let error {
print(error)
}
})
#endif
}
}
final class LiveViewController: UIViewController { final class LiveViewController: UIViewController {
var rtmpConnection:RTMPConnection = RTMPConnection() var rtmpConnection:RTMPConnection = RTMPConnection()
var rtmpStream:RTMPStream! var rtmpStream:RTMPStream!
@ -42,6 +61,7 @@ final class LiveViewController: UIViewController {
rtmpStream.audioSettings = [ rtmpStream.audioSettings = [
"sampleRate": sampleRate "sampleRate": sampleRate
] ]
rtmpStream.recorderDelegate = ExampleRecorderDelegate()
videoBitrateSlider?.value = Float(RTMPStream.defaultVideoBitrate) / 1024 videoBitrateSlider?.value = Float(RTMPStream.defaultVideoBitrate) / 1024
audioBitrateSlider?.value = Float(RTMPStream.defaultAudioBitrate) / 1024 audioBitrateSlider?.value = Float(RTMPStream.defaultAudioBitrate) / 1024

View File

@ -1,8 +1,5 @@
import Foundation import Foundation
import AVFoundation import AVFoundation
#if os(iOS)
import Photos
#endif
public protocol AVMixerRecorderDelegate: class { public protocol AVMixerRecorderDelegate: class {
var moviesDirectory:URL { get } var moviesDirectory:URL { get }
@ -251,20 +248,6 @@ extension DefaultAVMixerRecorderDelegate: AVMixerRecorderDelegate {
} }
open func didFinishWriting(_ recorder:AVMixerRecorder) { open func didFinishWriting(_ recorder:AVMixerRecorder) {
#if os(iOS)
guard let writer:AVAssetWriter = recorder.writer, shouldSaveToPhotoLibrary else {
return
}
PHPhotoLibrary.shared().performChanges({() -> Void in
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: writer.outputURL)
}, completionHandler: { (isSuccess, error) -> Void in
do {
try FileManager.default.removeItem(at: writer.outputURL)
} catch let error as NSError {
logger.error("\(error)")
}
})
#endif
} }
open func didStartRunning(_ recorder: AVMixerRecorder) { open func didStartRunning(_ recorder: AVMixerRecorder) {

View File

@ -124,6 +124,15 @@ open class NetStream: NSObject {
} }
} }
open var recorderDelegate: AVMixerRecorderDelegate? {
get {
return self.mixer.recorder.delegate
}
set {
self.mixer.recorder.delegate = newValue
}
}
#if os(iOS) || os(macOS) #if os(iOS) || os(macOS)
open func attachCamera(_ camera:AVCaptureDevice?, onError:((_ error:NSError) -> Void)? = nil) { open func attachCamera(_ camera:AVCaptureDevice?, onError:((_ error:NSError) -> Void)? = nil) {
lockQueue.async { lockQueue.async {