Playing a Streaming URL on TVML with TVJS

1.1k views Asked by At

I'm new on iOS, tvOS and Swift. I've been trying to play a video on tvOS App, but the video from a livestream URL which works fine on web. The TVML template and TVJS both works, even the App works if contains a single video URL(.mp4) but when I try with this streaming link it doesn´t work.

This is my TVJS

App.onLaunch = function(options){
    console.log("Hello TVML!");

    var resourceLoader = new ResourceLoaderJS(NativeResourceLoader.create());
    var initialDoc = resourceLoader.getDocument("hello.tvml");

    navigationDocument.pushDocument(initialDoc);

    initialDoc.addEventListener("play", handleEvent);
    initialDoc.addEventListener("select", handleEvent);
}

class ResourceLoaderJS {
    constructor(nativeResourceLoader) {
        this.nativeResourceLoader = nativeResourceLoader;
        this.domParser = new DOMParser();
    }

    getDocument(name) {
        var docString = this.nativeResourceLoader.loadBundleResource(name);

        return this.domParser.parseFromString(docString, "application/xml");
    }
}

function playVideo(title, url) {
    var player = new Player();

    var video = new MediaItem('video', url);
    video.title = title;

    player.playlist = new Playlist();
    player.playlist.push(video);

    player.play();
}

function handleEvent(event) {
    var buttonId = event.target.getAttribute("id");

    if(buttonId === "play") {
        playVideo("Hello TVML!","https://new.livestream.com/accounts...");
    }
}
1

There are 1 answers

0
Saurabh On

Yes it is possible to play livestream urls in apple tv tvml. You just have to specify livestream url in the url section of the code. I was able to play .m3u8 format without any modifications to the code. You can refer following link to get more info on creating the player: https://developer.apple.com/library/content/samplecode/TVMLAudioVideo/Listings/client_js_application_js.html