Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

how to play a video in swift

import UIKit
import AVKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //TODO : Make Sure Add and copy "SampleVideo.mp4" file in project before play
    }

    @IBAction func playLocalVideo(_ sender: Any) {

        guard let path = Bundle.main.path(forResource: "SampleVideo", ofType: "mp4") else {
            return
        }
        let videoURL = NSURL(fileURLWithPath: path)

        // Create an AVPlayer, passing it the local video url path
        let player = AVPlayer(url: videoURL as URL)
        let controller = AVPlayerViewController()
        controller.player = player
        present(controller, animated: true) {
            player.play()
        }
    }

}
Comment

PREVIOUS NEXT
Code Example
Swift :: xcode disable a button 
Swift :: swift go back to previous view controller 
Swift :: Decimal to Double conversion in Swift 
Swift :: blur background swiftUI 
Swift :: swift test if simulator 
Swift :: swift create array from range 
Swift :: swift for loop 
Swift :: swiftui console log 
Swift :: swift reload tableview 
Swift :: swift scroll to tableviewcell 
Swift :: swift scrollview scroll to bottom 
Swift :: tableview cell animation swift 
Swift :: change font of substring swift 
Swift :: swift date to string 
Swift :: uitableview scroll to bottom swift 
Swift :: how to add an underline to a textField swift 
Swift :: swift get current hour 
Swift :: uitextview text alignment 
Swift :: ForEach tabs swiftui 
Swift :: Play Video in AVPlayer ViewController Sample Code Swift 
Swift :: swift replace newlines with space 
Swift :: swift add enum storyboard 
Swift :: swift firebase realtime db class 
Swift :: table view content size not return correctly 
Swift :: swift multiple return values 
Swift :: Access Array Elements Using Swift Range 
Swift :: Swift Code Reusability 
Swift :: swift chuck array in peases 
Swift :: image copy swift extension 
Swift :: jsonserialization swift 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =