The Xcode7beta simulator works, but it doesn't play in the actual machine test.

Asked 2 years ago, Updated 2 years ago, 38 views

I am using MACBOOKAIR OS 10.11.3n Xcode-beta.
As I wrote in the title, I can't play the video on the actual machine test.
I tried various things on mov.mp4, quicktime, and CNVERTER, but it didn't work.

The program is as follows:

import Foundation
import AVKit
import AVFoundation

classViewController0:UIViewController{


    varplayerViewController = AVPlayerViewController()
    varplayerView = AVPlayer()


    override func viewDidLoad(){
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from anib.

    }

    override func viewDidAppear(animated:Bool) {
        let fileURL=NSURL(fileURLWithPath: "Here's a video file")
        playerView = AVPlayer (URL: fileURL)

        playerViewController.player=playerView

        self.presentViewController(playerViewController, animated:true){}

    }

    override funcdidReceiveMemoryWarning(){
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @ IBAction func playbuttontapped (sender:UIButton) {
        // Trigger the video to play
    }
}

I've been into it for about a week.
Thank you for your cooperation!!

xcode

2022-09-29 22:43

1 Answers

"It says ""I put a video file in here,"" but is the path of the video directly specified?"If so, the simulator can refer to the files on the Mac, but not from the actual machine.
Bundle video files into apps and use NSBundle to get the path as shown below.

iflet path=NSBundle.mainBundle().pathForResource("movie", ofType:"mp4"){
    let fileURL = NSURL (fileURLWithPath:path)
    playerView = AVPlayer (URL: fileURL)
    playerViewController.player=playerView
    self.presentViewController(playerViewController, animated:true, completion:nil)
}

Alternatively, I think it would be good to put the video file in a place accessible from the actual machine, create an NSURL for that URL, and play it.

Please forgive me if this is the case.

Additional information

import UIKit
import AVKit
import AVFoundation

classViewController:UIViewController {

    varplayerViewController = AVPlayerViewController()
    varplayerView = AVPlayer()

    override func viewDidLoad(){
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from anib.
    }

    override func viewDidAppear(animated:Bool) {
        super.viewDidAppear(animated)
        iflet path=NSBundle.mainBundle().pathForResource("name", ofType:"mp4"){
            let fileURL = NSURL (fileURLWithPath:path)
            playerView = AVPlayer (URL: fileURL)
            playerViewController.player=playerView
            self.presentViewController(playerViewController, animated:true){}
        }
    }

    override funcdidReceiveMemoryWarning(){
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func buttonTapped (sender:UIButton) {

    }
}


2022-09-29 22:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.