如何在纵向模式下以全屏尺寸播放视频?

我想在人像模式下在闪屏中播放一些视频 - 全屏。 这可能吗?请通过适当的解决方案指导我。如何在纵向模式下以全屏尺寸播放视频?

我在寻找迅速解决应用程序的委托

let splashScreenVC = viewController(withIdentifier: "identifier", inStoryboard: "storyboard:) as? SplashViewController 

window?.rootViewController = splashScreenVC

里面的视图控制器SplashViewController的

回答:

任何麻烦创建的UIView一个子类,具有AVPlayer和功能createBackground

import AVFoundation 

class BackgroundVideo: UIView {

var player: AVPlayer?

func createBackground(name: String, type: String) { }

}

那么你的createBackground可能是这样的:

实现视频循环

  • AVPlayerItemDidPlayToEndTime:10
    func createBackground(name: String, type: String) { 

    guard let path = Bundle.main.path(forResource: name, ofType: type) else { return }

    player = AVPlayer(url: URL(fileURLWithPath: path))

    player?.actionAtItemEnd = AVPlayerActionAtItemEnd.none;

    let playerLayer = AVPlayerLayer(player: player)

    playerLayer.frame = self.frame

    playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill

    self.layer.insertSublayer(playerLayer, at: 0)

    player?.seek(to: kCMTimeZero)

    player?.play()

    }

    那么您可以添加更多的东西,比如观察的通知。

  • UIApplicationWillEnterForeground用于控制视频循环,从后台恢复后。

最后你可能会附上这个BackgroundView,只要您需要:?假的闪屏,主屏幕,等等...

回答:

内didFinishLaunch方法,你可以在viewDidLoad方法播放视频。

func playVideo() { 

guard let videoPath = Bundle.main.path(forResource: "Redtaxi-splash", ofType:"mov") else {

return

}

let videoURL = URL(fileURLWithPath: videoPath)

let player = AVPlayer(url: videoURL)

playerViewController = AVPlayerViewController()

playerViewController?.player = player

playerViewController?.showsPlaybackControls = false

playerViewController?.view.frame = view.frame

playerViewController?.view.backgroundColor = .white

playerViewController?.view.contentMode = .scaleAspectFill

NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying(note:)),

name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)

view.addSubview((playerViewController?.view)!)

playerViewController?.player?.play()

}

回答:

SWIFT 3.0

你不能这样做,在默认的启动画面,但你可以做一些变通方法,以达致这。

首先你应该把你的视频的第一帧,这将是图像。

你可以使用Photoshop或任何其他图形工具。

现在,您可以将它设置为UIImageView中的默认启动画面。

现在制作一个UIViewController并启动它作为初始视图控制器。

并在下面的代码,以播放视频

private func playFullScreenVideo() { 

// drag your video file in project

// check if video file is available,if not return

guard let path = Bundle.main.path(forResource: "video", ofType:"mp4") else {

debugPrint("video.mp4 missing")

return

}

// create instance of videoPlayer with video path

let videoPlayer = AVPlayer(url: URL(fileURLWithPath: path))

// create instance of playerlayer with videoPlayer

let playerLayer = AVPlayerLayer(player: videoPlayer)

// set its videoGravity to AVLayerVideoGravityResizeAspectFill to make it full size

playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill

// add it to your view

playerLayer.frame = self.view.frame

playerView.layer.addSublayer(playerLayer)

// start playing video

videoPlayer?.play()

}

让我知道如果有这个

以上是 如何在纵向模式下以全屏尺寸播放视频? 的全部内容, 来源链接: utcz.com/qa/263678.html

回到顶部