【问题标题】:Playing a Streaming URL on TVML with TVJS使用 TVJS 在 TVML 上播放流式 URL
【发布时间】:2023-03-26 16:42:01
【问题描述】:

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

这是我的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...");
    }
}

【问题讨论】:

  • “流文件”是否与 tvOS 兼容 - 即 hls/m3u8 与 h264/aac 或类似文件。只是要求确保您没有尝试重播某些 Flash 内容或其他内容。
  • 要扩展 Baa 的评论,您的流媒体链接是在 .m3u8 还是 .smil 中?
  • 在哪里可以找到解决方案?

标签: swift streaming tvos tvml tvjs


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多