我是iOS,tvOS和Swift的新手。我一直试图在tvOS应用程序上播放视频,但视频来自一个直播网址,它在网络上工作得很好。TVML模板和TVJS都可以工作,即使应用程序包含一个单一的视频网址(.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...");
}
}发布于 2017-01-04 15:05:28
是的,可以在apple tv tvml中播放实况流urls。您只需在代码的url部分指定have url即可。我可以在不修改代码的情况下播放.m3u8格式。你可以参考下面的链接来获得更多关于创建播放器的信息:https://developer.apple.com/library/content/samplecode/TVMLAudioVideo/Listings/client_js_application_js.html
https://stackoverflow.com/questions/35609619
复制相似问题