使用TVJS在TVML上播放流媒体网址

时间:2016-02-24 18:00:33

标签: swift streaming tvos tvml tvjs

我是iOS,tvOS和Swift的新手。我一直在尝试在tvOS App上播放视频,但来自直播网址的视频在网络上运行良好。 TVML模板和TVJS都可以工作,如果包含单个视频URL(.mp4),即使App也可以工作,但是当我尝试使用这个流媒体链接时它不起作用。

这是我的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 个答案:

答案 0 :(得分:-1)

是的,可以在apple tv tvml中播放直播网址。您只需在代码的url部分指定livestream url即可。我能够播放.m3u8格式而无需对代码进行任何修改。 您可以参考以下链接获取有关创建播放器的更多信息: https://developer.apple.com/library/content/samplecode/TVMLAudioVideo/Listings/client_js_application_js.html