3

I am using VideoJs player 4.2

When i open a videojs player in safari browser in ios device , it works on native controls by default . When i pause the player, i display overlay buttons (links to go for other page) on video . If i click buttons it does not fire in ios . It works well in desktop browsers . If i set nativeControlsForTouch to false it displays custom controls . Here overlay buttons and custom controls works but it will be sluggish and i am not able scroll over video and it will be not smooth as compared with native controls . Please suggest me any idea

  1. If i use native controls , then overlay buttons has to work
  2. If i use custom controls , then video player will be as smooth as compared with native controls

Here is my code

videojs("ex_video",{"controls":true, "preload":"metadata","width":"auto", "height":"auto",
      "poster":"/images/test.png"},function(){
        var current_player=this; 
        current_player.imageOverlay({
          opacity: 0.5,
          height: '100%',
          width: '50%'
        });
      current_player.on("pause", function(){
        current_player.bigPlayButton.show();

      });
    current_player.on("play", function(){ 
      current_player.bigPlayButton.hide();
    });
});

overlay button code

(function(vjs) {
  var
   extend = function(obj) {
    var arg, i, k;
    for (i = 1; i < arguments.length; i++) {
     arg = arguments[i];
     for (k in arg) {
      if (arg.hasOwnProperty(k)) {
      obj[k] = arg[k];
      }
    }
  }
return obj;
},

defaults = {
  image_url: '',
  click_url: '',
  start_time: null,
  end_time: null,
  opacity: 0.7,
  height: '15%',
  width: '100%'
},

imageOverlay = function(options) {

var player = this,
    settings = extend({}, defaults, options || {}),
    showingImage = false;

if (settings.start_time === null)
  settings.start_time = 0;

if (settings.end_time === null)
  settings.end_time = player.duration() + 1;

overlay = {

  showImage: function() {
    if (showingImage) {

      return;
    }
    showingImage = true;
    var holderDiv = document.createElement('div');
    holderDiv.id = 'vjs-image-overlay-holder';
    holderDiv.style.height = settings.height;
    holderDiv.style.width = settings.width;
    holderDiv.style.opacity=settings.opacity;

    var overlayLbl1= document.createElement('label');
    overlayLbl1.setAttribute('class','heading-overlay-video');
    overlayLbl1.innerHTML= "Like this class? Why not:";
    var topVideoP=overlay.createEl(overlayLbl1);
    topVideoP.className=topVideoP.className+' top-video-control-overlay';
    holderDiv.appendChild(topVideoP);

    //Save to queue
    var overlayBtn1=document.createElement('button');
    overlayBtn1.value = 'Save to queue';
    overlayBtn1.innerHTML='Save to queue';
    overlayBtn1.setAttribute('class','white medium');
    holderDiv.appendChild(overlay.createEl(overlayBtn1));

    //Add to series button
    var overlayBtn2=document.createElement('button');
    overlayBtn2.value = 'Add to series';
    overlayBtn2.innerHTML='Add to series';
    overlayBtn2.setAttribute('class','white medium');
    holderDiv.appendChild(overlay.createEl(overlayBtn2));

    var overlayLbl2= document.createElement('label');
    overlayLbl2.innerHTML= "music credits";
    overlayLbl2.setAttribute('class','msg-blue');
    var btmVideoP=overlay.createEl(overlayLbl2);
    btmVideoP.className=btmVideoP.className+' bottom-video-control';
    holderDiv.appendChild(btmVideoP);



    player.el().appendChild(holderDiv);
  },
  hideImage: function() {
    if (!showingImage) {
      return;
    }
    showingImage = false;
    player.el().removeChild(document.getElementById('vjs-image-overlay-holder'));
  },
  createEl:function(ele_obj){
    var overlayP=document.createElement('p');
    overlayP.setAttribute('class','overlay-video-content-in');
    overlayP.appendChild(ele_obj);
    return overlayP ;
  }
};
var setTimeoutControl;

player.on('pause', function(){
 setTimeoutControl= setTimeout(function(){overlay.showImage()},5000);

});
player.on('play', function(){ 
  clearTimeout(setTimeoutControl);
  overlay.hideImage();
});    
}; 
vjs.plugin('imageOverlay', imageOverlay); 
}(window.videojs));
4

2 回答 2

1

By default HTML5 video in browser will open in native player in iPod,IPhone. You have to wrap the HTML content in webview and run it like a native application to view video in iPod,Iphone.

See this HTML5 inline video on iPhone vs iPad/Browser

So these two changes has to be done HTML

<video id="xxx" width="xx" height="xx" webkit-playsinline>

Obj-C

webview.allowsInlineMediaPlayback = YES;

In all other devices it will work fine with out these

于 2013-10-29T13:57:08.993 回答
1

It is better to use HammerJS(https://github.com/hammerjs/hammer.js). For EmberJS we have an add-on https://github.com/runspired/ember-gestures

于 2016-06-18T06:56:08.783 回答