我如何将视频剪辑放进我的故事板?我只看到:

另外,我应该把.mp4文件放在哪里?

最后,在启动时,为循环视频剪辑所包含的正确代码是什么。
//insert looping video clip here我熟悉Android /java,在那里可以做到这一点,没有问题。然而,我是非常新的快速和Xcode,所以我有麻烦。
发布于 2016-09-09 16:27:01
制作循环录影带:-
UIView添加到ViewController中,相应地设置约束。UIView为@IBOutlet
@IBOutlet弱var videoView : VideoPlay!//其中VideoPlay是视频播放器的CustomClassUIVew:VideoPlay创建自定义类
导入UIKit导入AVFoundation类VideoPlay: UIView {私有var player : AVPlayer!私有变量playerLayer : AVPlayerLayer!{super.init(框架: CGRectZero) self.initializePlayerLayer() }覆盖init(框架: CGRect) { super.init(frame: frame) self.initializePlayerLayer() self.autoresizesSubviews = false }所需init?(编码器aDecoder: NSCoder) {Super.init(编码器: aDecoder) self.initializePlayerLayer() }私有函数initializePlayerLayer() { playerLayer = AVPlayerLayer() playerLayer.backgroundColor = UIColor.whiteColor().CGColor playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill self.layer.addSublayer(playerLayer) playerLayer.frame = self.bounds} func playVideoWithURL(url: NSURL) {AVPlayer= AVPlayer(URL: url) player.muted = false playerLayer.player =playerLayer.player() loopVideo( player ) } func toggleMute() { player.muted = !player.muted }函数NSNotificationCenter.defaultCenter().addObserverForName(AVPlayerItemDidPlayToEndTimeNotification,isMuted() -> Bool {返回player.muted } func loopVideo(videoPlayer: AVPlayer) {对象: nil,queue: nil) { videoPlayer.seekToTime(kCMTimeZero) videoPlayer.play() }}中的通知videoView符合VideoPlay类,所以可以访问VideoPlay的全局函数。至于将视频文件保存在哪里,请将其保存在主包中,即:-在您的示例中,战斗培训师Pro文件夹
例如:-
toggleMute()
isMuted()
发布于 2019-01-31 06:33:25
一个客观的-C版本的德拉维迪亚的答案。还包含关键的layoutSubviews方法,这样视频层实际上与视图保持相同的大小!
#import "LBVideoView.h"
#import <AVFoundation/AVFoundation.h>
@interface LBVideoView ()
{
AVPlayer *_player;
AVPlayerLayer *_playerLayer;
}
@end
@implementation LBVideoView
- (instancetype)initWithFrame:(CGRect)frame
{
return [[super initWithFrame:frame] commonInit];
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
return [[super initWithCoder:aDecoder] commonInit];
}
- (instancetype)commonInit
{
_playerLayer = [AVPlayerLayer new];
_playerLayer.backgroundColor = UIColor.clearColor.CGColor;
_playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
[self.layer addSublayer:_playerLayer];
_playerLayer.frame = self.bounds;
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)playVideoWithURL:(NSURL*)url
{
_player = [AVPlayer playerWithURL:url];
_playerLayer.player = _player;
[_player play];
[self loopVideo];
}
- (void)loopVideo
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieEnded) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
}
- (void)movieEnded
{
[_player seekToTime:kCMTimeZero];
[_player play];
}
- (void)layoutSubviews
{
[super layoutSubviews];
_playerLayer.frame = self.bounds;
}
@endhttps://stackoverflow.com/questions/39415854
复制相似问题