【发布时间】: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