I want to play a local video with no controls in a UIView
I have imported the frameworks AVFoundation and AVKit into my code. I have also made my class for the UIView
, however, I am not sure on how to play the video in my UIView
with no controls. I have already found a way to play the video from the internet and that is not what I needed.
Asked
Active
Viewed 2,695 times
2
-
can you please show some work? What have you written for the work to be done? Always present your work so that we can find the issue Look at these links https://stackoverflow.com/questions/25932570/how-to-play-video-with-avplayerviewcontroller-avkit-in-swift – Gagan_iOS Aug 24 '17 at 12:19
-
check this out https://stackoverflow.com/questions/25348877/how-to-play-a-local-video-with-swift – rv7284 Aug 24 '17 at 12:20
-
you must go first with few tutorials like what controls are available for playing media file in your OS. Please look at these links http://www.theappguruz.com/blog/play-audio-and-video-using-avfoundation-framework-in-swift http://www.techotopia.com/index.php/IOS_8_Video_Playback_using_AVPlayer_and_AVPlayerViewController – Gagan_iOS Aug 24 '17 at 12:23
-
you can play local videos with AVplayer – Nauman Malik Aug 24 '17 at 12:23
1 Answers
1
In swift 3.0, try this code.
//for Playing Video
@IBAction func btnvideoPlayClicked(_ sender: UIButton) {
self.videoPlay()
}
func videoPlay()
{
let playerController = AVPlayerViewController()
playerController.delegate = self
let bundle = Bundle.main
let moviePath: String? = bundle.path(forResource: "SoSorry", ofType: "mp4")
let movieURL = URL(fileURLWithPath: moviePath!)
let player = AVPlayer(url: movieURL)
playerController.player = player
self.addChildViewController(playerController)
self.view.addSubview(playerController.view)
playerController.view.frame = self.view.frame
player.play()
}

Berlin
- 2,115
- 2
- 16
- 28