Swift 使用TVJS在TVML上播放流式URL
我是iOS、tvOS和Swift的新手。我一直在尝试在tvOS应用程序上播放一段视频,但这段视频来自一个livestream URL,在web上运行良好。TVML模板和TVJS都能工作,即使应用程序包含一个视频URL.mp4也能工作,但当我尝试使用这个流链接时,它不起作用 这是我的TVJSwift 使用TVJS在TVML上播放流式URL,swift,streaming,tvos,tvml,tvjs,Swift,Streaming,Tvos,Tvml,Tvjs,我是iOS、tvOS和Swift的新手。我一直在尝试在tvOS应用程序上播放一段视频,但这段视频来自一个livestream URL,在web上运行良好。TVML模板和TVJS都能工作,即使应用程序包含一个视频URL.mp4也能工作,但当我尝试使用这个流链接时,它不起作用 这是我的TVJ App.onLaunch = function(options){ console.log("Hello TVML!"); var resourceLoader = new ResourceL
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...");
}
}
是的,可以在apple tv tvml中播放livestream URL。您只需在代码的url部分指定LiveStreamURL。我能够在不修改代码的情况下播放.m3u8格式。 您可以参考以下链接以获取有关创建播放机的更多信息:
流媒体文件是否与tvOS兼容-即hls/m3u8与h264/aac或类似文件兼容。只是要求确保您没有试图重播某些flash内容或其他内容。要扩展Baa的评论,您的流媒体链接是否在.m3u8或.smil中?在哪里可以找到解决方案?