-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SCNRenderer not rendering the AVPlayer #2
Comments
Hi, can you share some example code? |
Thanks for your quick response, Please find the below sample code. import UIKit
import GVRKit
import GVRSCNRenderer
import SceneKit
import AVKit
import CoreMotion
import GLKit
import SpriteKit
class VRViewController: UIViewController {
@IBOutlet weak var rendererView: UIView!
var player: AVPlayer?
var playerObserver: NSKeyValueObservation?
var scene: SCNScene!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
guard let scene = SCNScene(named: "room-preset.scn") else { return }
self.scene = scene
let renderer = GVRSCNRenderer(scene: scene)
renderer.pause(false)
renderer.rendererDelegate = self
// renderer.vrModeEnabled = true
let view = GVRRendererView(renderer: renderer)
// view?.vrModeEnabled = true
view?.paused = false
view?.translatesAutoresizingMaskIntoConstraints = false
view?.frame = rendererView.bounds
rendererView.addSubview(view!)
NSLayoutConstraint(item: view!, attribute: .leading, relatedBy: .equal, toItem: rendererView, attribute: .leading, multiplier: 1.0, constant: 0).isActive = true
NSLayoutConstraint(item: view!, attribute: .trailing, relatedBy: .equal, toItem: rendererView, attribute: .trailing, multiplier: 1.0, constant: 0).isActive = true
NSLayoutConstraint(item: view!, attribute: .top, relatedBy: .equal, toItem: rendererView, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
NSLayoutConstraint(item: view!, attribute: .bottom, relatedBy: .equal, toItem: rendererView, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeLeft
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeLeft
}
override var shouldAutorotate: Bool {
return true
}
func startNewPlayer() {
if player != nil {
return
}
let asset = AVURLAsset(url: URL(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8")!)
let playerItem = AVPlayerItem(asset: asset, automaticallyLoadedAssetKeys: [#keyPath(AVAsset.tracks), #keyPath(AVAsset.duration)])
player = AVPlayer(playerItem: playerItem)
playerObserver = playerItem.observe(\.status, options: [.new, .old], changeHandler: {[weak self] (playerItem, change) in
guard let strongSelf = self else {return}
if playerItem.status == .readyToPlay {
strongSelf.playerObserver?.invalidate()
strongSelf.playerObserver = nil
let videoSize = playerItem.asset.tracks(withMediaType: .video).first?.naturalSize ?? CGSize(width: 640, height: 480)
var videoNode: SKVideoNode!
let videoScene = SKScene(size:videoSize)
videoNode = SKVideoNode(avPlayer: strongSelf.player!)
videoNode.position = CGPoint(x: videoScene.size.width/2, y: videoScene.size.height/2)
videoNode.size = videoScene.size
videoNode.yScale = -1
videoNode.play()
videoScene.addChild(videoNode)
guard let video = strongSelf.scene.rootNode.childNode(withName: "TVSCREEN", recursively: true) else { return }
video.geometry?.firstMaterial?.diffuse.contents = videoScene
video.geometry?.firstMaterial?.isDoubleSided = false
}
})
}
}
extension VRViewController: SCNSceneRendererDelegate {
func renderer(_ renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: TimeInterval) {
startNewPlayer()
}
} |
Thanks, I will look into it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When we use AVPlayer in the scenekit, that is not rendering. Just audio only playing.
If you have any solution please let me know.
The text was updated successfully, but these errors were encountered: