【问题标题】:How to add video to iOS app intro screen like Uber如何将视频添加到 Uber 等 iOS 应用程序介绍屏幕
【发布时间】:2015-11-12 02:41:49
【问题描述】:

希望将视频添加到我的应用介绍屏幕,例如优步应用。我确信还有其他人。

我发现这个使用 gif 和 UIWebView,但不确定这是否是最佳解决方案。我绝对不想使用图像并将它们拼接在一起(如果这是首选方法,我宁愿没有视频)。

https://medium.com/swift-programming/ios-make-an-awesome-video-background-view-objective-c-swift-318e1d71d0a2

【问题讨论】:

标签: ios objective-c


【解决方案1】:

这是我在我的应用程序 Letsplay 中使用的,来自 Aslam 的答案将起作用,但使用自 IOS 9.0 起已弃用的 MPmoviePlayerController。 我还设置了视频重力,以便您的视频将填满整个帧,这意味着没有黑色边框。

NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"icebergs" ofType:@"mp4"];
NSURL *videoURL = [[NSURL alloc] initFileURLWithPath: videoPath];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:[AVURLAsset URLAssetWithURL:videoURL options:nil]];

AVPlayer* videoPlayer = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer* videoPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:videoPlayer];
[videoPlayerLayer setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

[self.view.layer addSublayer:videoPlayerLayer];
[videoPlayerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

[videoPlayer play];

如果您不想要声音,请记住将播放器静音

[videoPlayer setMuted:YES];

【讨论】:

    【解决方案2】:

    我还没有尝试过代码,但它应该可以工作。它通常取视频文件的路径并将其添加到视图控制器。您可能需要设置坐标和大小。虽然我在这里使用过视频,但更喜欢 GIF。

    - (void)viewDidAppear:(BOOL)animated
    {   
        [self loadVideoInBackgroundOfView];
    
    }
    
    
    -(void)loadVideoInBackgroundOfView{
        MPMoviePlayerController*  videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[self getTheVideoPath]];
        [videoPlayer.view setFrame:self.view.bounds];
        [self.view insertSubview:moviePlayer.view atIndex:0];
        [videoPlayer prepareToPlay];
        [videoPlayer play];
    
    }
    
    -(NSURL*)getTheVideoPath{
        NSString *path = [[NSBundle mainBundle] pathForResource:@"VideoFileName" ofType:@"mp4"];
        NSURL *URL = [NSURL fileURLWithPath:path];
        return URL;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-14
      • 2021-09-24
      • 2015-08-26
      • 1970-01-01
      相关资源
      最近更新 更多