Hi guys, in this article i'll show you how to play video with 'video player' in Swift iOS programming via xCode.
That's the whole code. Not let's examine it piece by piece.
That part of code helps us to import AVKit framework to our project.
Think this part of code like HTML tags. This is where we work and we put our codes inside of curly brackets.
That part of code helps us to import .mp4 video file from our folders. You can also use .avi, .mov, etc.
That part of codes tells us that video is in the variable of videoPlayer. We need to process that player with codes of AVKit framework to our project.
That part of code opens our videoPlayer.
Result
Kod:
import AVKit
class ViewController: UIViewController {
[USER=794421]IBA[/USER]ction func buttonismi(_ sender: UIButton) {
if let path = Bundle.main.path(forResource: "videoismi", ofType: "mp4")
{
let video = AVPlayer(url: URL(fileURLWithPath: path))
let videoPlayer = AVPlayerViewController()
videoPlayer.player = video
present(videoPlayer, animated: true, completion: {
video.play()
})
}
}
That's the whole code. Not let's examine it piece by piece.
Kod:
import AVKit
That part of code helps us to import AVKit framework to our project.
Kod:
class ViewController: UIViewController {
Think this part of code like HTML tags. This is where we work and we put our codes inside of curly brackets.
Kod:
if let path = Bundle.main.path(forResource: "videoismi", ofType: "mp4")
{
That part of code helps us to import .mp4 video file from our folders. You can also use .avi, .mov, etc.
Kod:
let video = AVPlayer(url: URL(fileURLWithPath: path))
let videoPlayer = AVPlayerViewController()
videoPlayer.player = video
That part of codes tells us that video is in the variable of videoPlayer. We need to process that player with codes of AVKit framework to our project.
Kod:
present(videoPlayer, animated: true, completion: {
video.play()
})
}
That part of code opens our videoPlayer.
Result
Source: https://www.turkhackteam.org/ios-ge...ideo-player-ile-video-oynatma-akovskiniz.html
Translator: R4V3N
Moderatör tarafında düzenlendi: