我希望能够在启用纸板模式的情况下在我的应用上启动视频。
我已经成功安装了Gooogle VR播放器SDK,我创建了一个启用全屏模式启动视频的按钮,同时也取得了成功!!
我想要另一个按钮,这次是从Cardboard模式开始的视频,但是我无法让它工作!!
以下是我的控制器的代码:
//
// FeedDetails.swift
// MobileAppDemo
//
// Created by Mikko Hilpinen on 31.10.2016.
// Copyright © 2016 Mikkomario. All rights reserved.
//
import UIKit
import FirebaseAuth
import FirebaseDatabase
import FirebaseStorage
import SwiftKeychainWrapper
import SwiftyJSON
class FeedDetailsController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var textView: UITextView!
@IBOutlet weak var titleLabel: UITextView!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet var videoVRView: GVRVideoView!
@IBOutlet var imageVRView: GVRPanoramaView!
@IBOutlet var cardboardVRview: GVRCardboardView!
@IBOutlet var imageLabel: UILabel!
@IBOutlet var videoLabel: UILabel!
enum Media {
static var photoArray = ["test.jpg"]
static let videoURL = "https:/myserver.com/videolight.mp4"
}
var currentView: UIView?
var currentDisplayMode = GVRWidgetDisplayMode.embedded
var isPaused = true
override func viewDidLoad() {
super.viewDidLoad()
imageLabel.isHidden = true
imageVRView.isHidden = true
videoLabel.isHidden = true
videoVRView.isHidden = true
cardboardVRview.isHidden = true
imageVRView.load(UIImage(named: Media.photoArray.first!),
of: GVRPanoramaImageType.mono)
imageVRView.enableCardboardButton = true
imageVRView.enableFullscreenButton = true
// imageVRView.delegate = self
videoVRView.load(from: URL(string: Media.videoURL))
videoVRView.enableCardboardButton = true
videoVRView.enableFullscreenButton = true
// videoVRView.delegate = self
cardboardVRview.load(from: URL(string: Media.videoURL))
cardboardVRview.enableCardboardButton = true
cardboardVRview.enableFullscreenButton = true
// change to your specification
textView.isEditable = false
textView.isSelectable = false
titleLabel.isEditable = false
titleLabel.isSelectable = false
textView.text = posts[selectedIndexPath].caption
titleLabel.text = posts[selectedIndexPath].title
Storage.getImage(with: posts[selectedIndexPath].imageUrl){
postPic in
self.imageView.image = postPic
}
}
// TRIGER VIDEO 360 //
@IBAction func videoButton(_ sender: UIButton) {
if let button = self.videoVRView.subviews[1] as? UIButton {
button.sendActions(for: .touchUpInside)
}
}
func widgetView(widgetView: GVRWidgetView!, didLoadContent content: AnyObject!) {
self.videoVRView.isHidden = false;
}
// END TRIGGER 360 //
// TRIGER CARDBOARD //
@IBAction func cardboardButton(_ sender: UIButton) {
if let button = self.cardboardVRview.subviews[1] as? UIButton {
button.sendActions(for: .touchUpInside)
}
}
func widgetViewcardboard(widgetView: GVRCardboardView!, didLoadContent content: AnyObject!) {
self.cardboardVRview.isHidden = false
}
// END CARDBOARD //
@IBAction func closeButton(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
func refreshVideoPlayStatus() {
if currentView == videoVRView && currentDisplayMode != GVRWidgetDisplayMode.embedded {
videoVRView?.resume()
isPaused = false
} else {
videoVRView?.pause()
isPaused = true
}
}
func setCurrentViewFromTouch(touchPoint point:CGPoint) {
if imageVRView!.frame.contains(point) {
currentView = imageVRView
}
if videoVRView!.frame.contains(point) {
currentView = videoVRView
}
}
}
extension FeedDetailsController: GVRWidgetViewDelegate {
func widgetView(_ widgetView: GVRWidgetView!, didLoadContent content: Any!) {
if content is UIImage {
imageVRView.isHidden = false
imageLabel.isHidden = false
} else if content is NSURL {
videoVRView.isHidden = false
videoLabel.isHidden = false
refreshVideoPlayStatus()
}
}
func widgetView(_ widgetView: GVRWidgetView!, didFailToLoadContent content: Any!, withErrorMessage errorMessage: String!) {
print(errorMessage)
}
func widgetView(_ widgetView: GVRWidgetView!, didChange displayMode: GVRWidgetDisplayMode) {
currentView = widgetView
currentDisplayMode = displayMode
refreshVideoPlayStatus()
if currentView == imageVRView && currentDisplayMode != GVRWidgetDisplayMode.embedded {
view.isHidden = true
} else {
view.isHidden = false
}
}
func widgetViewDidTap(_ widgetView: GVRWidgetView!) {
guard currentDisplayMode != GVRWidgetDisplayMode.embedded else {return}
if currentView == imageVRView {
Media.photoArray.append(Media.photoArray.removeFirst())
imageVRView?.load(UIImage(named: Media.photoArray.first!), of: GVRPanoramaImageType.mono)
} else {
if isPaused {
videoVRView?.resume()
} else {
videoVRView?.pause()
}
isPaused = !isPaused
}
}
}
extension FeedDetailsController: GVRVideoViewDelegate {
func videoView(_ videoView: GVRVideoView!, didUpdatePosition position: TimeInterval) {
OperationQueue.main.addOperation() {
if position >= videoView.duration() {
videoView.seek(to: 0)
videoView.resume()
}
}
}
}
class TouchView: UIView {
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
if let FeedDetailsController = viewController() as? FeedDetailsController , event?.type == UIEventType.touches {
FeedDetailsController.setCurrentViewFromTouch(touchPoint: point)
}
return true
}
func viewController() -> UIViewController? {
if self.next!.isKind(of: FeedDetailsController.self) {
return self.next as? UIViewController
} else {
return nil
}
}
}
我做了相同的过程,开始以全屏模式播放视频,但是通过调用GVRCardboardView而不是GVRVideoView,你可以看到,但它确实有效...我在这些行上有错误:
cardboardVRview.load(from: URL(string: Media.videoURL))
cardboardVRview.enableCardboardButton = true
cardboardVRview.enableFullscreenButton = true
对于第一行'静态成员'加载'不能在GVRCardboardView类型的实例中使用
和'GVRCardboardView'类型的值没有成员'enableFullscreenButton'和'enableCardboardBUtton'用于其他两行。 。
有人知道我怎么做这个吗?
太棒了!谢谢你们!
答案 0 :(得分:2)
如果您希望默认情况下以Cardboard模式启动。您应该这样设置视图。意思是你要输入:
ssh://git@my-repo.com:7999/my-project.git