目标是在没有控件的情况下在UIView内播放视频文件(*.mp4).
它将作为ViewController和其他控件的背景/壁纸,即tableview,文本字段,图像将显示在视图上,带有视频回放.
有什么更好的方法呢?谢谢
目标是使用Swift在设备上捕获全屏视频.在下面的代码中,视频捕获似乎全屏发生(录制相机预览时使用全屏),但视频的渲染以不同的分辨率发生.特别是对于5S,看起来捕获发生在320x568但渲染发生在320x480.
如何捕获和呈现全屏视频?
视频捕获代码:
private func initPBJVision() {
// Store PBJVision in var for convenience
let vision = PBJVision.sharedInstance()
// Configure PBJVision
vision.delegate = self
vision.cameraMode = PBJCameraMode.Video
vision.cameraOrientation = PBJCameraOrientation.Portrait
vision.focusMode = PBJFocusMode.ContinuousAutoFocus
vision.outputFormat = PBJOutputFormat.Preset
vision.cameraDevice = PBJCameraDevice.Back
// Let taps start/pause recording
let tapHandler = UITapGestureRecognizer(target: self, action: "doTap:")
view.addGestureRecognizer(tapHandler)
// Log status
print("Configured PBJVision")
}
private func startCameraPreview() {
// Store PBJVision in var for convenience
let vision = PBJVision.sharedInstance()
// Connect PBJVision …Run Code Online (Sandbox Code Playgroud) 我是Swift语言的新手.我想开发简单的电影播放器应用程序进行学习.我在我的项目中添加了一些电影(".avi,.flv,.f4u ......哪种格式最好).我的观点很简单.我的视图上有一个按钮.IT称为"播放".当用户点按时在那个按钮上电影将开始.
另外我还需要播放音频文件,比如mp3或.mid文件.你能告诉我如何在Swift中做到这一点吗?如果你用例子解释,它将是完美的.
编辑
我不是要求所有代码.当我尝试将Objective C代码转换为Swift时,我感到困惑.我想知道如何在Swift中开发下面的代码?
NSString *path = [[NSBundle mainBundle] pathForResource:@"eminem1" ofType:@"mp4"];
MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];
Run Code Online (Sandbox Code Playgroud) 如何在iOS中将视频作为背景播放?我关注了这个问题:如何使用Swift播放本地视频?,但AV Player ViewController是一个控制器,不能让我决定包含视频的视图的位置和大小。它始终采用一些预定义的值。
我一直在尝试找出如何使用 循环播放多个视频AVPlayerLooper,但它们templateItem采用 type 参数AVPlayerItem而不是[AVPlayerItem]。我目前正在使用 anAVQueuePlayer来显示视频,但我需要循环播放它。
到目前为止,这是我的代码:
class MyVC: UIViewController {
@IBOutlet weak var playerView: UIView!
lazy var backgroundVideoPlayer = AVQueuePlayer()
// View Controller related code (viewDidLoad, etc.) is taken out for brevity.
private func loadBackgroundVideosRandomly() -> [AVPlayerItem] {
let mainBundle = Bundle.main
let movieURLs = [mainBundle.url(forResource: "Boop Burj Al Arab", withExtension: "mov"),
mainBundle.url(forResource: "Boop Dubai", withExtension: "mov"),
mainBundle.url(forResource: "Boop Dubai Clock", withExtension: "mov"),
mainBundle.url(forResource: "Boop Dubai Lake", withExtension: "mov")].shuffled()
let …Run Code Online (Sandbox Code Playgroud) ios ×5
swift ×3
avfoundation ×2
avplayer ×2
video ×2
objective-c ×1
pbjvision ×1
repeat ×1
uiview ×1