Saturday, 8 July 2023

Video Error: Check video URL is valid in SWIFT

 This the code to find the Video URL is valid or not.

Before adding the video URL to AVplayer, check whether AVplayer can play video using that url using AVAsset.



func getVideoPlayer(url: String) -> AVPlayer? {
    guard let url = URL(string: url) else {
        print("url not found")
            return nil
        }
    //test if video is playable
    if AVAsset(url: url).isPlayable {
        let player = AVPlayer(url: url)
        return player
    } else {
        return nil
    }
}

No comments:

Setting Up Multiple App Targets in Xcode from a Single Codebase

 To create two different apps (like "Light" and "Regular") from the same codebase in Xcode, you can follow these steps b...