Sunday, January 28, 2024
HomeiOS Developmentios - AVPLayer with SwiftUI for taking part in video

ios – AVPLayer with SwiftUI for taking part in video


I needed to play AVPlayer like youtube shorts movies, I’ve been utilizing the hyperlinks from the youtube shorts with there videoId’s, however AVPlayer shouldn’t be supporting these hyperlinks. is there any likelihood to transform these shorts id hyperlinks to supportable format for AVPlayer

    @State var currentVideoIndex: Int
    @State var participant: AVPlayer
    @State var playerList: [AVPlayer] = []
    
    let videoURLs = [
    URL(string: "https://youtube.com/shorts/-3qL9gC_FE4?si=oZjHfoWx1KrIFTO-")!,
    URL(string: "https://youtube.com/shorts/s2wfgJuexyk?si=r3LrspHMqgCzbqWw")!,
    URL(string: "https://youtube.com/shorts/c1IomVJi7Vo?si=xjdV58E3I4g95sHP")!
    ]

    VideoPlayer(participant: participant) {
        
    }.gesture(DragGesture(minimumDistance: 20, coordinateSpace: .native).onEnded { gesture in
        participant.quantity = 0
        if gesture.translation.width < 0 {
            currentVideoIndex = (currentVideoIndex + 1)%videoURLs.depend
        } else if gesture.translation.width > 0 {
            currentVideoIndex = (currentVideoIndex - 1)%videoURLs.depend
        }
        setupPlayer(index: currentVideoIndex)
    })
        .edgesIgnoringSafeArea(.all)
        .onAppear {
            playerList.append(AVPlayer(url: videoURLs[0]))
            playerList.append(AVPlayer(url: videoURLs[1]))
            playerList.append(AVPlayer(url: videoURLs[2]))
        }
    }



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments