2015-10-07 139 views
0

我有VideoViewController.swift,我想在secondviewcontroller播放視頻這樣的照片(不是全屏幕),當我按下按鈕modalviewcontroller在迅速

http://i.stack.imgur.com/xBB4d.png]

我嘗試使用模式視圖控制器但它不起作用。問題是什麼?

這是源代碼: VideoViewController.swift

import UIKit 
import AVKit 
import AVFoundation 

class VideoViewController: UIViewController { 

    @IBOutlet weak var AVPlayerView: UIView! 

    override func shouldAutorotate() -> Bool { 
     return false 
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // yoon // from web 
     let sampleURL = NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")! 
     let player = AVPlayer(URL: sampleURL) 


     let playerLayer = AVPlayerLayer(player: player) 

     let videoWidth = 320 
     let videoHeigh = 180 
     let screenWidth = self.view.frame.size.width 
     let screenHeigh = self.view.frame.size.height 

     playerLayer.frame = CGRectMake(
      (screenWidth/2 - CGFloat(videoWidth/2)), 
      (screenHeigh/2 - CGFloat(videoHeigh/2)), 
      CGFloat(videoWidth), 
      CGFloat(videoHeigh)) 

     AVPlayerView.layer.addSublayer(playerLayer) 


     player.play() 

     //AVPlayerView.backgroundColor = UIColor.blackColor() 
    } 

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

} 

的viewController。 swift

import UIKit 
import Social 
import AVKit 
import AVFoundation 

class ViewController: UIViewController, SideBarDelegate { 

    @IBOutlet weak var AVPlayerView: UIView! 

    override func shouldAutorotate() -> Bool { 
     return false 
    } 

    @IBAction func videoStream(sender: AnyObject) { 


     self.modalTransitionStyle = UIModalTransitionStyle.CoverVertical 
     // Cover Vertical is necessary for CurrentContext 
     self.modalPresentationStyle = .CurrentContext 
     // Display on top of current UIView 


     self.presentViewController(VideoViewController(), animated: true, completion: nil) 
     //self.preferredContentSize = CGSizeMake(320, 200) 
} 
+0

好像你使用的是廈門國際銀行或情節串連圖板,如果你需要從情節提要/加載廈門國際銀行,你必須使用相應的分配,而不是VideoViewController()。 – abintom

回答

0

在代碼中有幾個強有力的解包選項。在打開包裝之前,您需要確保這些插口已經放好。以下將播放第二個視頻中的視頻,但你需要添加框架和你想要的其他東西。第一個VC是好的,因爲它是

import UIKit 
import AVKit 
import AVFoundation 

class VideoViewController: AVPlayerViewController { 

    @IBOutlet weak var AVPlayerView: UIView! 

    override func shouldAutorotate() -> Bool { 
     return false 
    } 

    private func playVideo() { 
     player = AVPlayer(URL: NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!) 
    } 

    override func viewDidAppear(animated: Bool) { 
     super.viewDidAppear(animated) 
     playVideo() 
    } 

}