Coder Social home page Coder Social logo

droidfix's Introduction

Droidfix.js

This is a small example which provides a correction for the way the Google Android platform handles the ended and pause events relating to HTML5 video.

Default (wrong) Behavior

The Android platform, when it begins playback of a new HTML5 video, opens a new "video viewing" window that is only partially connected to the main browser window. To return to the browser window, the user must use the device's back button.

When the user performs this action, an "ended" event is fired on the video element regardless of the position of the playback when the user hit the back button. This is contrary to the spec which states the following precondition for firing the ended event:

currentTime equals the end of the media resource

A more appropriate event to fire would be a "pause" event; however, the Android device doesn't do so.

What this example does

In this example, I'm demonstrating how you can "fake" knowing whether the ended event is real or not by tracking the time index of the video. We have to store this value locally as, in addition to firing an ended event when it shouldn't, Android also resets the currentTime of the video object to 0 when exiting the player.

If it is determined that the video was paused and not ended, a custom pause event is generated and fired to trigger any handlers bound to pause. If it is determined that that the video has really ended, the list of callbacks provided will be called and sent the ended event.

Usage

Note: As it currently stands in the 0.1 state, this code provides a great example of how to get around this issue; it's not meant to be deployed as is

Two things to note about current use:

  1. This really only supports a single video object as it's currently built
  2. Handlers for "ended" events must be added using droidfix.addEndedListener rather than element.addEventListener("ended").

Ultimately, these issues should be resolved in a later version.

Caveats

There are a few issues, most notably that if the user scrubs back to an earlier time index in the video after having past the threshold, the video will be considered "ended" when the user pauses.

Coming Soon...ish

I want to convert this into two thing:

  1. A jQuery plugin that leverages bind() and provides custom functionality
  2. Part of a standalone library for handling issues with mobile video

But that will come in time; please feel free to fork and implement those things yourself and I will accept pull requests with quality code. :)

droidfix's People

Contributors

bcrescimanno avatar

Watchers

James Cloos avatar 李逸期 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.