 
 extension ViewController : AVCaptureVideoDataOutputSampleBufferDelegate,AVCaptureAudioDataOutputSampleBufferDelegate{
     
-    //两个代理实际采集代理方法一致  所以要区分
+ 
     //丢弃掉的
     func captureOutput(_ captureOutput: AVCaptureOutput!, didDrop sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
         
     }
+    
+    //两个代理实际采集代理方法一致  所以要区分
     //实际输出的
     func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
+        print(connection.output)
         
-        if videoconnection == connection {
-            print("视频采集")
-        }else{
-            print("音频采集")
-        }
-        
+//        if videoOutput?.connection(withMediaType: AVMediaTypeVideo) == connection {
+//             print("视频采集")
+//        }else{
+//            print("音频采集")
+//        }
     }
 }

//
//  Created by Ari on 2017/6/22.
//  Copyright © 2017年 com.Ari. All rights reserved.
//

import UIKit
import AVFoundation

        guard let devices = AVCaptureDevice.devices() as?[AVCaptureDevice] else{return}
        guard let device = devices.filter({$0.position == oritation}).first else {return}
        guard let newInput = try? AVCaptureDeviceInput(device: device) else {return}
        
        let newOutput = AVCaptureVideoDataOutput()
        newOutput.setSampleBufferDelegate(self, queue: DispatchQueue.global())
        
        //移除之前的input 添加新的input
        session.removeInput(videoInput)
        session.removeOutput(videoOutput)
        addInputOutput2session(newInput, newOutput)
        self.videoInput = newInput
        videoOutput = newOutput
//        videoconnection = newOutput.connection(withMediaType: AVMediaTypeVideo)
        
    }
    
