ios - 视频不在启动画面上播放

标签 ios iphone mpmovieplayercontroller splash-screen

我正在尝试显示带有视频的启动画面。为此,我有两个疑问:

  1. 我已经创建了闪屏 View Controller 并在应用程序启动时加载它。但是在我的闪屏 VC 显示任何修复之前,白屏会显示几秒钟?
  2. 我正在播放的视频只显示黑屏。我猜不出我做错了什么。下面是它的代码。

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
    
    let vc = SplashScreenVC(nibName: "SplashScreenVC", bundle: nil)
    let rootViewController = UINavigationController(rootViewController: vc)
    self.window?.rootViewController = rootViewController
    self.navigationController?.navigationBarHidden = true
    self.window?.makeKeyAndVisible()
    
    // Override point for customization after application launch.
    return true
    

    class SplashScreenVC: UIViewController {
    
    override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.navigationBarHidden = true
        playVideo()
    }
    
    func playVideo() {
    
      let moviePath = NSBundle.mainBundle().pathForResource("animationVideo", ofType: "mp4")
      let movieUrl = NSURL.fileURLWithPath(moviePath!)
      let moviePlayer : MPMoviePlayerController = MPMoviePlayerController(contentURL: movieUrl)
      moviePlayer.prepareToPlay()
      let vV = self.view.viewWithTag(SplashScreenUITags.videoView.rawValue)! as UIView
      moviePlayer.controlStyle = MPMovieControlStyle.None
      moviePlayer.scalingMode = MPMovieScalingMode.Fill
      moviePlayer.movieSourceType  = MPMovieSourceType.File;
      moviePlayer.view.frame = vV.bounds
    
      vV.addSubview(moviePlayer.view)
      moviePlayer.play()
    
      NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("moviePlayBackDidFinish:"), name: MPMoviePlayerPlaybackDidFinishNotification, object: moviePlayer)
    
    }
    }
    

最佳答案

您的一个解决方案是显示启动画面 (IMG),然后播放您喜欢的视频。

要快速播放视频,请使用 AV Foundation https://developer.apple.com/av-foundation/

You cannot get rid of the static splash image. While it is shown, the OS is loading the application and instantiating stuff until it is ready to call your UIApplicationDelegate. So all you can do is either use no splash (black screen for a few seconds) or make your movie start exactly with the shown splash screen so it looks like the static image would suddenly animate.

To get rid of the black screen while the movie loads, you can try to make the player transparent and have an UIImageView behind the player that shows the splash image. The behavior would be this:

Splash screen is shown (static image). Application is loaded. You see the UIImageView, also showing the splash screen. On top of it is the transparent movie player. Movie player finally has loaded the move and starts playing it. At least in theory, this should cause the effect that the static image suddenly starts animating.

But if you don't use a splash screen at all (a lot of games do that), then it doesn't matter that the movie player is showing a black screen at first, you wouldn't notice.

Regarding showing the splash screen in an UIImageView: unfortunately, you have to test the interface rotation and load the image manually, there's no way to query which splash screen was shown. If you only support one interface orientation (again, a lot of games do this) you don't have this problem, of course.

关于ios - 视频不在启动画面上播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35479529/

相关文章:

ios - 如何使用 MPMoviePlayer 播放 YouTube 视频?

iphone - 用于 iPhone 测试的 CoverStory?

iPhone 操作系统内存问题 - 如何调试?

ios - MPMoviePlayerController 完成按钮,横向

iphone - MPMoviePlayerController 为流媒体电影创建自定义缓冲区进度条

iphone - Zip 套件与 Xcode 4.3 的集成

ios - UITableView 防止滚动时重新加载

iOS 7 UIBarButton 后退按钮箭头颜色

iphone - UICollectionView制作EPG

ios - render回调函数和input回调函数有什么区别