Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3721

How to display video without default controls, but use your own. YoutubeAPI. Swift. AVPlayer

$
0
0

I'm trying to get a video from YouTube API. But I don't need embedded video. Or rather, I do not need the controls that are in the version with embedded video. I need to manage my own. Does YouTube provide such an opportunity? Is there any adequate way to implement this? I'm already thinking about a fake view that will be on top of the video so that the default buttons are not available. Please tell me! Here is my request:

func fetchPlaylistWith(_ playlistID: String) {    let url = K.Networking.BASIC_PLAYLIST_URL    let parameters: [String: String] = ["part": "snippet", "maxResults": "10", "playlistId": playlistID, "key": K.Networking.API_KEY]    playlistRequestWith(url, and: parameters)}private func playlistRequestWith(_ url: String, and parameters: [String: String]) {    AF.request(url, parameters: parameters)        .validate()        .responseDecodable(of: PlaylistData.self) { response in            guard let videos = response.value else { return }            var videoItems = [VideoModel]()            for item in videos.items {                let title = item.snippet.title                let imageURL = item.snippet.thumbnails.medium.url                let videoID = item.snippet.resourceId.videoId                let newVideo = VideoModel(title: title, imageURL: imageURL, videoID: videoID)                videoItems.append(newVideo)            }            delegate?.retrievePlaylist(videos: videoItems)        }}

and the link that I got from the response and which I send to the player.

override func viewDidLoad() {    super.viewDidLoad()    configUI()    let url = URL(string: "https://www.youtube.com/watch?v=JVuq8BHIlbQ")!    player = AVPlayer(url: url)    playerLayer = AVPlayerLayer(player: player)    playerLayer.videoGravity = .resize    videoView.layer.addSublayer(playerLayer)}override func viewDidAppear(_ animated: Bool) {    super.viewDidAppear(animated)    player.play()}override func viewDidLayoutSubviews() {    super.viewDidLayoutSubviews()    playerLayer.frame = videoView.bounds}

Also, I will attach a screenshot of how it should be.

enter image description here


Viewing all articles
Browse latest Browse all 3721

Latest Images

Trending Articles



Latest Images