0

我正在使用 PHPickerViewControllerDelegate 获取 url。我已经确认我的 url 已正确输入到代码中,但是当我播放视频节点时,没有视频显示并且我没有听到任何声音,所以这不是分层问题。我们可以将此选项称为 1。

更新:我认为我可以通过使用 AVPlayer 来解决问题,所以我尝试了两种额外的方法,(选项 2)将视频文件放入项目中,这有效但不能解决我从本地目录中提取文件的问题。(选项 3)使用本地目录中的视频,但不起作用。SKVideoNode 框显示但没有视频播放。

这告诉我,它与本地目录 url 有关。我需要包括一些隐私的东西,所以视频显示了吗?我很近,但似乎很远。

Optional(file:///private/var/mobile/Containers/Data/Application/3D99929D-CFC4-418A-B215-3AE463F3AD38/tmp/.com.apple.Foundation.NSItemProvider.WMPrvs/RPReplay_Final1617465667.mp4)

import Foundation
import SpriteKit
import GameplayKit
import PhotosUI

class AnimationInventory18: SKScene {
 
   var chosenCharacterSceneUse1: CharacterSkin?
    var chosenBackgroundSceneUse1: BackgroundSkin?
    var selectedTextSceneUse1: String?
    var chosenImageSceneUse1: UIImage?
    var chosenLivePhotoSceneUse1: PHLivePhoto?
    var chosenVideoSceneUse1: URL?

    //MARK: First Party Class Initializers
    init(size: CGSize, chosenChateracterSceneUse: CharacterSkin?,selectedTextSceneUse: String?, chosenBackgroundSceneUse: BackgroundSkin?, chosenImageSceneUse: UIImage?, chosenLivePhotoSceneUse: PHLivePhoto?, chosenVideoSceneUse: URL? ){
        super.init(size:size)
        self.chosenCharacterSceneUse1 = chosenChateracterSceneUse
        self.selectedTextSceneUse1 = selectedTextSceneUse
        self.chosenBackgroundSceneUse1 = chosenBackgroundSceneUse
        self.chosenImageSceneUse1 = chosenImageSceneUse
        self.chosenLivePhotoSceneUse1 = chosenLivePhotoSceneUse
        self.chosenVideoSceneUse1 = chosenVideoSceneUse
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func niceToMeetYou() {
        videoPlay()     
    }

    func videoPlay(){
        // below print statement outputs - *Optional(file:///private/var/mobile/Containers/Data/Application/3D99929D-CFC4-418A-B215-3AE463F3AD38/tmp/.com.apple.Foundation.NSItemProvider.WMPrvs/RPReplay_Final1617465667.mp4)*
        print(chosenVideoSceneUse1)

        let video2 = SKVideoNode(url: chosenVideoSceneUse1!)
     
        video2.position = CGPoint(x: 90, y: -40)
        video2.zPosition = 1
        video2.xScale = 5
        video2.yScale = 5

        // below print statement outputs - *<SKVideoNode> name:'(null)' position:{90, -40} size:{0, 0} rotation:0.00*
        print(video2)
        addChild(video2)
        video2.play()

        //Plays but isnt ideal since pulling from project files instead of local director
        let urlStr = Bundle.main.path(forResource: "TryToHaveANiceDay-20210322", ofType: "mov")
        print(urlStr)
        let url = NSURL(fileURLWithPath: urlStr!)
        let player2 = AVPlayer(url: url as URL)
        let videoNode = SKVideoNode(avPlayer: player2)
        
        
        videoNode.position = CGPoint(x: 0, y: 0)
        videoNode.zPosition = 100
        videoNode.size = CGSize(width: 100, height: 100)
        videoNode.xScale = 1
        videoNode.yScale = 1

        addChild(videoNode)
        videoNode.play()
        

        // SKVideoNode displays but content does not
        let player = AVPlayer(url: chosenVideoSceneUse1! as URL)
        print(player)
        let video3 = SKVideoNode(avPlayer: player)

        video3.position = CGPoint(x: 0, y: 0)
        video3.zPosition = 100
        video3.size = CGSize(width: 100, height: 100)
        video3.xScale = 1
        video3.yScale = 1        

        addChild(video3)
        video3.play()

    //MARK: Override functions
    override func didMove(to view: SKView) {
        niceToMeetYou()
        
    }

    }

4

0 回答 0