将MediaItem属性显示到我的tvml模板中?

时间:2016-01-09 09:11:58

标签: javascript properties tvos apple-tv tvml

我正在尝试制作苹果电视应用。

我正在使用tvOS Developer库中的示例代码:

https://developer.apple.com/library/tvos/samplecode/TVMLAudioVideo/Introduction/Intro.html

我想在application.js中显示这些数据:

video.title = metadata.title;
video.subtitle = metadata.subtitle;
video.description = metadata.description;
video.artworkImageURL = metadata.artworkImageURL;

var Videos = {
    video: [{
        title: "AV BipBop",
        subtitle: "Sample HLS Stream",
        description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
        artworkImageURL: "",
        contentRatingDomain: "movie",
        contentRatingRanking: 400,
        url: "https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8"
    }],

在我的index.xml.js

 /*
    Copyright (C) 2015 Apple Inc. All Rights Reserved.
    See LICENSE.txt for this sample’s licensing information

    Abstract:
    A list template shows a list of items on the right, such as movies or TV shows. Focus on one to see its related content on the left, such as its artwork or description.
*/
var Template = function() {
    return '<?xml version="1.0" encoding="UTF-8"?>' +
    '<document>' +
        '<listTemplate>' +
            '<list>' +
                '<header>' +
                    '<title>Playback examples</title>' +
                '</header>' +
                '<section>' +
                    '<listItemLockup id="video">' +
                        '<title> (Here video title )   </title>' +
                    '</listItemLockup>' +
                    '<listItemLockup id="playlist">' +
                        '<title>Playlist</title>' +
                    '</listItemLockup>' +
                '</section>' +
            '</list>' +
        '</listTemplate>' +
    '</document>';
}

我试过:$ {title}和$ {video.title},但它不起作用。

1 个答案:

答案 0 :(得分:0)

您尝试引用的对象超出范围。您可以修改模板以将字典作为参数。

var Template = function(video) {
var doc = '<?xml version="1.0" encoding="UTF-8"?>' +
'<document>' +
    '<listTemplate>' +
        '<list>' +
            '<header>' +
                '<title>Playback examples</title>' +
            '</header>' +
            '<section>' +
                '<listItemLockup id="video">' +
                    '<title>${video["title"]}</title>' +
                '</listItemLockup>' +
                '<listItemLockup id="playlist">' +
                    '<title>Playlist</title>' +
                '</listItemLockup>' +
            '</section>' +
        '</list>' +
    '</listTemplate>' +
'</document>';
return doc;
}

您需要修改调用以在ResourceLoader.js中创建此模板,如下所示:

var resource = Template.call(self, myVideoDictionary);