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:
Post a Comment