2017-02-13 94 views
1

我希望能夠在啓用紙板模式的應用程序中啓動視頻。Google VR Player SDK(GVRSDK)默認情況下以carboard模式啓動?

我已經成功安裝Gooogle企業VR播放器的SDK,我創建了一個按鈕,開始啓用在全屏模式下的視頻,成功以及!

我想另一個按鈕,開始這次在紙板模式下的視頻,但我不能讓它工作!

下面是具有按鈕我的控制器代碼:

// 
// 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你可以看到,但它doenst工作......我有那些行錯誤:

 cardboardVRview.load(from: URL(string: Media.videoURL)) 
    cardboardVRview.enableCardboardButton = true 
    cardboardVRview.enableFullscreenButton = true 

的第一行「靜態成員‘負荷’不能在類型的實例中使用GVRCardboardView

,'GVRCardboardView'類型的值對於其他兩行沒有成員'enableFullscreenButton'和'enableCardboardBUtton'。 。

有沒有人知道我可以做這個工作?

它將太棒了!感謝你們 !

回答

2

如果你想默認啓動Cardboard模式。你應該這樣設置視圖。意思是你會輸入:

videoVRView.displayMode = GVRWidgetDisplayMode.fullscreenVR 
相關問題