Madu
Madu

Reputation: 5019

AVPlayer hear audio but no video for Mp4 file TVOs

I am trying to play a remote mp4 file which is there on the web using AVPlayer on TVOS. When i try to play the video i can hear the audio but there is no video and whole screen is blank. I have read many articles about that which say that i should turn off ATS (I did that. However my url is HTTPS) and i set the frame also in viewDidLayoutSubviews, but still unable to make it work. Here is my code, if some could help me in solving this issue then it will be a great help since i am scratching my head here and there since yesterday.

I am not writing the exact Url for some privacy issues.

import Foundation
import UIKit
import AVKit

class PlayViewController : UIViewController {

    var moviePlayer : AVPlayer?

    override func viewDidLoad() {
        super.viewDidLoad()
        print("In PlayViewController View Did Load")
        let movieUrl =  NSURL.init(string: "Some Amazon Url.mp4")!
        moviePlayer = AVPlayer.init(URL: movieUrl)
    }


    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        let avPlayerLayer = AVPlayerLayer.init(layer: moviePlayer!)
        avPlayerLayer.frame = CGRectMake(0.0, 0.0, 1024.0, 768.0)
        self.view.layer.addSublayer(avPlayerLayer)
        moviePlayer?.play()
    }


}

Upvotes: 2

Views: 965

Answers (1)

ssb
ssb

Reputation: 36

The URL is somehow indicating HTTP(S) streaming, right? Well, I also made my experience while trying to play a video stream from a set-top-box like a DVB receiver through its Web-Interface. It did not work (at least when I tried with tvOS 9.0). According to Apple documentation the video streams have to comply to the HTTP Streaming protocol they describe. It requires, that HTTP streams are split into small chunks of video snippets of a few seconds length. See https://developer.apple.com/library/tvos/referencelibrary/GettingStarted/AboutHTTPLiveStreaming/about/about.html

At the end I gave up and switched to use VLCKit from videolan.org. After some back and forth this works fine in my App (vuplusTV).

Upvotes: 0

Related Questions