AVKit Integration in iOS 18 – #30DaysOfSwift

Day 23: AVKit Integration – Playing Videos and Media in SwiftUI 🎬

Today, we’ll explore how to integrate AVKit into your SwiftUI project.

AVKit is the framework that lets you play videos and audio seamlessly with built-in controls.

Comments for Cu…


This content originally appeared on DEV Community and was authored by Vaibhav Dwivedi

Day 23: AVKit Integration – Playing Videos and Media in SwiftUI 🎬

Today, we’ll explore how to integrate AVKit into your SwiftUI project.

AVKit is the framework that lets you play videos and audio seamlessly with built-in controls.

Image description

Comments for Customization:

  • player.play(): This starts video playback.
  • cornerRadius(10): This rounds the corners of the video view, making it visually appealing.
  • frame(height: 300): The video player is confined to a specific height, ensuring a clean layout.

Here's the code for the implementation shown:

import AVKit
import SwiftUI

struct VideoPlayerView: View {
    private var player = AVPlayer(url: URL(string: "https://www.example.com/samplevideo.mp4")!)

    var body: some View {
        VStack {
            VideoPlayer(player: player)
                .frame(height: 300)
                .cornerRadius(10)

            HStack {
                Button("Play Video") {
                    player.play()
                }
                .font(.headline)
                .foregroundColor(.white)
                .padding()
                .background(Color.blue)
                .cornerRadius(8)

                Button("Pause Video") {
                    player.pause()
                }
                .font(.headline)
                .foregroundColor(.white)
                .padding()
                .background(Color.red)
                .cornerRadius(8)
            }
            .padding(.top, 20)
        }
        .padding()
    }
}

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Welcome to Video Player")
                .font(.largeTitle)
                .padding()

            VideoPlayerView()
        }
    }
}

The full series is available on my profile and the components can also be found at shipios.app/components.

Happy Coding! 🎨


This content originally appeared on DEV Community and was authored by Vaibhav Dwivedi


Print Share Comment Cite Upload Translate Updates
APA

Vaibhav Dwivedi | Sciencx (2024-10-31T16:38:00+00:00) AVKit Integration in iOS 18 – #30DaysOfSwift. Retrieved from https://www.scien.cx/2024/10/31/avkit-integration-in-ios-18-30daysofswift/

MLA
" » AVKit Integration in iOS 18 – #30DaysOfSwift." Vaibhav Dwivedi | Sciencx - Thursday October 31, 2024, https://www.scien.cx/2024/10/31/avkit-integration-in-ios-18-30daysofswift/
HARVARD
Vaibhav Dwivedi | Sciencx Thursday October 31, 2024 » AVKit Integration in iOS 18 – #30DaysOfSwift., viewed ,<https://www.scien.cx/2024/10/31/avkit-integration-in-ios-18-30daysofswift/>
VANCOUVER
Vaibhav Dwivedi | Sciencx - » AVKit Integration in iOS 18 – #30DaysOfSwift. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/31/avkit-integration-in-ios-18-30daysofswift/
CHICAGO
" » AVKit Integration in iOS 18 – #30DaysOfSwift." Vaibhav Dwivedi | Sciencx - Accessed . https://www.scien.cx/2024/10/31/avkit-integration-in-ios-18-30daysofswift/
IEEE
" » AVKit Integration in iOS 18 – #30DaysOfSwift." Vaibhav Dwivedi | Sciencx [Online]. Available: https://www.scien.cx/2024/10/31/avkit-integration-in-ios-18-30daysofswift/. [Accessed: ]
rf:citation
» AVKit Integration in iOS 18 – #30DaysOfSwift | Vaibhav Dwivedi | Sciencx | https://www.scien.cx/2024/10/31/avkit-integration-in-ios-18-30daysofswift/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.