2015-10-20 39 views
0

使用MenuBar模板,並有菜單工作。但是,請將鼠標懸停在視頻等頂級菜單項上。視頻頁面自動加載在演示區域內。但是當你去選擇一個視頻時,它會在用戶點擊之前開始自動播放,從而禁止用戶選擇其他視頻而不是第一個視頻。我只想讓視頻不要自動播放,並等待用戶的輸入。我嘗試了一個eventListener,但它被忽略。我不知道該怎麼做。蘋果tvOS Javascript停止視頻自動播放

Presenter.js

var Presenter = { 
    defaultPresenter: function(xml) { 
     if(this.loadingIndicatorVisible) { 
      navigationDocument.replaceDocument(xml, this.loadingIndicator); 
      this.loadingIndicatorVisible = false; 
     } else { 
      navigationDocument.pushDocument(xml); 
     } 
    }, 

    modalDialogPresenter: function(xml) { 
     navigationDocument.presentModal(xml); 
    }, 

    menuBarItemPresenter: function(xml, ele) { 
     var feature = ele.parentNode.getFeature("MenuBarDocument"); 

     if (feature) { 
      var currentDoc = feature.getDocument(ele); 
      if (!currentDoc) { 
       feature.setDocument(xml, ele); 
      } 
     } 
    }, 

    load: function(event) { 
     console.log(event); 

     var self = this, 
      ele = event.target, 
      templateURL = ele.getAttribute("template"), 
      presentation = ele.getAttribute("presentation"); 
      videoURL = ele.getAttribute("videoURL"); 

     if(videoURL) { 
      var player = new Player(); 
      var playlist = new Playlist(); 
      var mediaItem = new MediaItem("video", videoURL); 

      player.playlist = playlist; 
      player.playlist.push(mediaItem); 
      player.present(); 
     } 

     if (templateURL) { 
      self.showLoadingIndicator(presentation); 
      resourceLoader.loadResource(templateURL, 
       function(resource) { 
        if (resource) { 
         var doc = self.makeDocument(resource); 
         doc.addEventListener("select", self.load.bind(self)); 
         doc.addEventListener("highlight", self.load.bind(self)); 

         if (self[presentation] instanceof Function) { 
          self[presentation].call(self, doc, ele); 
         } else { 
          self.defaultPresenter.call(self, doc); 
         } 
        } 
       } 
      ); 
     } 
    }, 

    makeDocument: function(resource) { 
     if (!Presenter.parser) { 
      Presenter.parser = new DOMParser(); 
     } 

     var doc = Presenter.parser.parseFromString(resource, "application/xml"); 
     return doc; 
    }, 

    showLoadingIndicator: function(presentation) { 
     if (!this.loadingIndicator) { 
      this.loadingIndicator = this.makeDocument(this.loadingTemplate); 
     } 

     if (!this.loadingIndicatorVisible && presentation != "modalDialogPresenter" && presentation != "menuBarItemPresenter") { 
      navigationDocument.pushDocument(this.loadingIndicator); 
      this.loadingIndicatorVisible = true; 
     } 
    }, 

    removeLoadingIndicator: function() { 
     if (this.loadingIndicatorVisible) { 
      navigationDocument.removeDocument(this.loadingIndicator); 
      this.loadingIndicatorVisible = false; 
     } 
    }, 

    loadingTemplate: `<?xml version="1.0" encoding="UTF-8" ?> 
     <document> 
      <loadingTemplate> 
      <activityIndicator> 
       <text>Loading...</text> 
      </activityIndicator> 
      </loadingTemplate> 
     </document>` 
} 

--- --- application.js中

var resourceLoader; 
App.onLaunch = function(options) { 
    var javascriptFiles = [ 
     `${options.BASEURL}js/ResourceLoader.js`, 
     `${options.BASEURL}js/Presenter.js` 
    ]; 
    evaluateScripts(javascriptFiles, function(success) { 
     if (success) { 
      resourceLoader = new ResourceLoader(options.BASEURL); 
      var index = resourceLoader.loadResource(`${options.BASEURL}templates/CalvaryTVMenuBar.xml.js`, 
       function(resource) { 
        var doc = Presenter.makeDocument(resource); 
        doc.addEventListener("select", Presenter.load.bind(Presenter)); 
        navigationDocument.pushDocument(doc); 
       }); 
     } else { 
      var alert = createAlert("Evaluate Scripts Error", "There was an error attempting to evaluate the external JavaScript files.\n\n Please check your network connection and try again later."); 
      navigationDocument.presentModal(alert); 
      throw ("Playback Example: unable to evaluate scripts."); 
     } 
    }); 
} 

var createAlert = function(title, description) { 
    var alertString = `<?xml version="1.0" encoding="UTF-8" ?> 
     <document> 
      <alertTemplate> 
      <title>${title}</title> 
      <description>${description}</description> 
      </alertTemplate> 
     </document>` 
    var parser = new DOMParser(); 
    var alertDoc = parser.parseFromString(alertString, "application/xml"); 
    return alertDoc 
} 

回答

1

嗨喬希

嘗試刪除您在加載附加的亮點事件該文檔使用resourceLoader.loadResource方法。

看來,要連接這兩個事件

  1. doc.addEventListener( 「選擇」,self.load.bind(個體經營));
  2. doc.addEventListener(「highlight」,self.load.bind(self));

嘗試刪除第二個。

+0

謝謝Hari。謝謝!我有它的工作。大聲笑,我很沮喪。謝謝! –