Skip to content

Commit 3c9abf5

Browse files
committed
Fix: For Android when changing audio and immediately playing.
1 parent 26e2455 commit 3c9abf5

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jPlayer",
3-
"version": "2.5.4",
3+
"version": "2.5.5",
44
"main": [
55
"./jquery.jplayer/jquery.jplayer.js",
66
"./skin/pink.flag/jplayer.pink.flag.css"

jplayer.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"html5",
1212
"streaming"
1313
],
14-
"version": "2.5.4",
14+
"version": "2.5.5",
1515
"author": {
1616
"name": "Mark J Panaghiston",
1717
"email": "markp@happyworm.com",

jquery.jplayer/jquery.jplayer.js

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* http://opensource.org/licenses/MIT
88
*
99
* Author: Mark J Panaghiston
10-
* Version: 2.5.4
11-
* Date: 9th January 2014
10+
* Version: 2.5.5
11+
* Date: 8th March 2014
1212
*/
1313

1414
/* Code verified using http://www.jshint.com/ */
@@ -470,7 +470,7 @@
470470
$.jPlayer.prototype = {
471471
count: 0, // Static Variable: Change it via prototype.
472472
version: { // Static Object
473-
script: "2.5.4",
473+
script: "2.5.5",
474474
needFlash: "2.5.2",
475475
flash: "unknown"
476476
},
@@ -794,6 +794,17 @@
794794
$.jPlayer.focus = this;
795795
}
796796

797+
// A fix for Android where older (2.3) and even some 4.x devices fail to work when changing the *audio* SRC and then playing immediately.
798+
this.androidFix = {
799+
setMedia: false, // True when media set
800+
play: false, // True when a progress event will instruct the media to play
801+
pause: false, // True when a progress event will instruct the media to pause at a time.
802+
time: NaN // The play(time) parameter
803+
};
804+
if($.jPlayer.platform.android) {
805+
this.options.preload = this.options.preload !== 'auto' ? 'metadata' : 'auto'; // Default to metadata, but allow auto.
806+
}
807+
797808
this.formats = []; // Array based on supplied string option. Order defines priority.
798809
this.solutions = []; // Array based on solution string option. Order defines priority.
799810
this.require = {}; // Which media types are required: video, audio.
@@ -1261,6 +1272,15 @@
12611272
if(self.internal.cmdsIgnored && this.readyState > 0) { // Detect iOS executed the command
12621273
self.internal.cmdsIgnored = false;
12631274
}
1275+
self.androidFix.setMedia = false; // Disable the fix after the first progress event.
1276+
if(self.androidFix.play) { // Play Android audio - performing the fix.
1277+
self.androidFix.play = false;
1278+
self.play(self.androidFix.time);
1279+
}
1280+
if(self.androidFix.pause) { // Pause Android audio at time - performing the fix.
1281+
self.androidFix.pause = false;
1282+
self.pause(self.androidFix.time);
1283+
}
12641284
self._getHtmlStatus(mediaElement);
12651285
self._updateInterface();
12661286
self._trigger($.jPlayer.event.progress);
@@ -1691,6 +1711,11 @@
16911711
this._resetGate();
16921712
this._resetActive();
16931713

1714+
// Clear the Android Fix.
1715+
this.androidFix.setMedia = false;
1716+
this.androidFix.play = false;
1717+
this.androidFix.pause = false;
1718+
16941719
// Convert all media URLs to absolute URLs.
16951720
media = this._absoluteMediaUrls(media);
16961721

@@ -1719,6 +1744,11 @@
17191744
self.html.audio.gate = true;
17201745
self._html_setAudio(media);
17211746
self.html.active = true;
1747+
1748+
// Setup the Android Fix - Only for HTML audio.
1749+
if($.jPlayer.platform.android) {
1750+
self.androidFix.setMedia = true;
1751+
}
17221752
} else {
17231753
self.flash.gate = true;
17241754
self._flash_setAudio(media);
@@ -2590,9 +2620,16 @@
25902620
var self = this,
25912621
media = this.htmlElement.media;
25922622

2623+
this.androidFix.pause = false; // Cancel the pause fix.
2624+
25932625
this._html_load(); // Loads if required and clears any delayed commands.
25942626

2595-
if(!isNaN(time)) {
2627+
// Setup the Android Fix.
2628+
if(this.androidFix.setMedia) {
2629+
this.androidFix.play = true;
2630+
this.androidFix.time = time;
2631+
2632+
} else if(!isNaN(time)) {
25962633

25972634
// Attempt to play it, since iOS has been ignoring commands
25982635
if(this.internal.cmdsIgnored) {
@@ -2622,7 +2659,9 @@
26222659
_html_pause: function(time) {
26232660
var self = this,
26242661
media = this.htmlElement.media;
2625-
2662+
2663+
this.androidFix.play = false; // Cancel the play fix.
2664+
26262665
if(time > 0) { // We do not want the stop() command, which does pause(0), causing a load operation.
26272666
this._html_load(); // Loads if required and clears any delayed commands.
26282667
} else {
@@ -2632,7 +2671,12 @@
26322671
// Order of these commands is important for Safari (Win) and IE9. Pause then change currentTime.
26332672
media.pause();
26342673

2635-
if(!isNaN(time)) {
2674+
// Setup the Android Fix.
2675+
if(this.androidFix.setMedia) {
2676+
this.androidFix.pause = true;
2677+
this.androidFix.time = time;
2678+
2679+
} else if(!isNaN(time)) {
26362680
try {
26372681
if(!media.seekable || typeof media.seekable === "object" && media.seekable.length > 0) {
26382682
media.currentTime = time;
@@ -2656,6 +2700,8 @@
26562700

26572701
this._html_load(); // Loads if required and clears any delayed commands.
26582702

2703+
// This playHead() method needs a refactor to apply the android fix.
2704+
26592705
try {
26602706
if(typeof media.seekable === "object" && media.seekable.length > 0) {
26612707
media.currentTime = percent * media.seekable.end(media.seekable.length-1) / 100;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jplayer",
3-
"version": "2.5.4",
3+
"version": "2.5.5",
44
"description": "The jQuery HTML5 Audio / Video Library",
55
"homepage": "http://www.jplayer.org/",
66
"keywords": [

0 commit comments

Comments
 (0)