在iOS

时间:2016-08-08 15:12:14

标签: ios swift video

我正在制作视频日记应用,播放视频(视频包含问题)来自本地图书馆的NO AUDIO,并记录通过相机和麦克风响应视频的用户。

视频和录像机需要在按下UI按钮时启动,并在完成后停止录制。到目前为止,在一些教程之后,当按下按钮时,我可以使用AVPlayerViewController从本地库中播放视频,并在视频完成时显示通知。但是,我尝试使用UIImagePickerController激活相机会干扰视频的播放。有没有人知道教程或对我如何进行有一些建议?

import UIKit
import AVKit
import AVFoundation
import MobileCoreServices

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    var  playerController :  AVPlayerViewController!
    let imagePicker: UIImagePickerController! = UIImagePickerController()
    let saveFileName = "/test.mp4"

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func play(sender: AnyObject) {
        let path = NSBundle.mainBundle().pathForResource("Video", ofType: "mov")
        let url = NSURL(fileURLWithPath:  path!)
        let player = AVPlayer(URL: url)
        playerController = AVPlayerViewController()

        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.didfinishPlaying(_:)), name: AVPlayerItemDidPlayToEndTimeNotification, object: player.currentItem)

        playerController.player = player
        playerController.player?.play()
//        imagePicker.sourceType = .Camera
//        imagePicker.cameraDevice = .Front
//        imagePicker.sourceType = .Camera
//        imagePicker.mediaTypes = [kUTTypeMovie as String]
//        imagePicker.allowsEditing = false
//        imagePicker.delegate = self
//          presentViewController(imagePicker, animated: false, completion: {})

        self.presentViewController(playerController, animated: true, completion: nil)


    }

    func didfinishPlaying(note : NSNotification){
        playerController.dismissViewControllerAnimated(true, completion: nil)

        let alertView = UIAlertController(title: "Finished", message: "Video finished", preferredStyle: .Alert)

    alertView.addAction(UIAlertAction(title: "Okay", style: .Default, handler: nil))
    self.presentViewController(alertView, animated: true, completion: nil)

    }
}

感谢您抽出宝贵时间来查看我的问题。

0 个答案:

没有答案