ios – AVPLayer with SwiftUI for playing video


I wanted to play AVPlayer like youtube shorts videos, I have been using the links from the youtube shorts with there videoId’s, but AVPlayer is not supporting those links. is there any chance to convert those shorts id links to supportable format for AVPlayer

    @State var currentVideoIndex: Int
    @State var player: 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(player: player) {
        
    }.gesture(DragGesture(minimumDistance: 20, coordinateSpace: .local).onEnded { gesture in
        player.volume = 0
        if gesture.translation.width < 0 {
            currentVideoIndex = (currentVideoIndex + 1)%videoURLs.count
        } else if gesture.translation.width > 0 {
            currentVideoIndex = (currentVideoIndex - 1)%videoURLs.count
        }
        setupPlayer(index: currentVideoIndex)
    })
        .edgesIgnoringSafeArea(.all)
        .onAppear {
            playerList.append(AVPlayer(url: videoURLs[0]))
            playerList.append(AVPlayer(url: videoURLs[1]))
            playerList.append(AVPlayer(url: videoURLs[2]))
        }
    }

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img