1

youtube.comがロードされているIOSUIviewで自分のボタンを使用してビデオを一時停止しようとしています。私は運がなくてyoutubeapiと対話しようとしてきました。

プレーヤーと対話するために独自のコードを挿入することを検討しています(swfobjectオブジェクト?そうですか?)。player / swfobjectに接続しようとしましたが、成功しませんでした。そして、もう一度明確にするために、私は自分自身のビデオを新しいWebビューに埋め込みたくありません。(私はそれを行う方法を知っています。それを行うためのクールな方法は、Tubeplayerプラグインを使用することです)。

だから私がしたいのはこれです:

  1. モバイルアプリから呼び出す一時停止JavaScript関数を挿入します。
  2. 次に、関数は次のようなことを行います。

    var theSwfobject = window.swfobject; //**Find the youtube video object for reuse.**
    theSwfobject.PauseVideo();
    

簡単な質問は次のとおりです。youtube.comでyoutubeビデオオブジェクトを見つけて再利用するにはどうすればよいですか(IOSから呼び出してビデオを一時停止するpause()関数を挿入できるようにするため)。

4

1 に答える 1

2

あなたの最新のコメントに基づいて、私はJavaScriptで何かをすることを期待しています。これは、このインスタンスでビデオ要素を制御するためにセットアップする小さなAPIです。ビデオ要素にはIDがないように見えるため、getElementsByTagNameを使用します。

var myVideoController = {};

myVideoController = (function() {

  "use strict";      

  var muted = false;

  var module = {

    //Grabs video element by tag name and assumes there would only be one if it exists 
    getVideoElement : function() {
      var videoElements = document.getElementsByTagName('video');
      var videoElement = null;

      if(videoElements[0]) {
        videoElement = videoElements[0];
      }

      return videoElement;
    },

    /** 
     * Wrapper to make interacting with html5 video element functions easier.
     * @param functionName - name of function to invoke on the video element
     * @params - any additional parameters will be fed as arguments to the functionName function
     */
    callVideoFunction : function(functionName) {
      var videoElement = module.getVideoElement();
      var functionArguments = [];

      if(videoElement !== null) {
        functionArguments = module.getSubArguments(arguments, 1);

        if(functionArguments.length > 0) {
          videoElement[functionName](functionArguments);
        } else {
          videoElement[functionName]();
        }
      }
    },

    setVideoProperty : function(propertyName, propertyValue) {
      var videoElement = module.getVideoElement();

      if(videoElement !== null) {
        videoElement[propertyName] = propertyValue;
      }
    },

    /* Helper method to grab array of function arguments for callVideoFunction
       since the arguments object in functions looks like an array but isn't
       so .shift() is not defined */
    getSubArguments : function (args, indexFrom) {

      var subArguments = [];

      for(var i = indexFrom; i < args.length; i++) {
        subArguments.push(args[i]);
      }

      return subArguments;
    },

    //Pause the video
    pauseVideo : function() {
      module.callVideoFunction('pause');
    },

    //Play the video
    playVideo : function() {
      module.callVideoFunction('play');
    },

    //Mute/Unmute video
    flipVideoMute : function() {
      muted = !muted;
      module.setVideoProperty('muted', muted);
    }
  };

  return module;

})();

http://www.w3.org/2010/05/video/mediaevents.htmlでテストしました。ここで、w3はAPIの使用に関するフィードバックを含むHTML5ビデオを設定しています。上記のコードをjavascriptコンソールにコピーし、次のようにコマンドを実行しました。

//Start video
myVideoController.playVideo();

//Pause video
myVideoController.pauseVideo();

//Restart video
myVideoController.playVideo();

//Mute video
myVideoController.flipVideoMute();

//Unmute video
myVideoController.flipVideoMute();
于 2013-03-07T17:16:39.623 に答える