Bug 1305869 - don't display media control for very short sound. r=sebastian

For the short sound, we don't want to show the media control interface for them, eg. game effect.
Therefore, we check the media's duration to decide whether need to notify Java side "Tab:MediaPlaybackChange" or not.

MozReview-Commit-ID: 8PlQl2w2BSI

--HG--
extra : rebase_source : c4e5d38eae1dba22af268ea575dd6c9672e7cf9f
This commit is contained in:
Alastor Wu 2016-11-01 12:22:39 +08:00
Родитель 6890b35c2b
Коммит d075282bff
1 изменённых файлов: 43 добавлений и 13 удалений

Просмотреть файл

@ -4385,6 +4385,29 @@ Tab.prototype = {
// for now anyway.
},
ShouldNotifyMediaPlaybackChange: function(inactive) {
// We don't want to show the media control interface for the short sound
// which duration is smaller than the threshold. The basic unit is second.
// Note : the streaming format's duration is infinite.
const mediaDurationThreshold = 1.0;
let audioElements = this.browser.contentDocument.getElementsByTagName("audio");
for each (let audio in audioElements) {
if (audio.paused == inactive && audio.duration > mediaDurationThreshold) {
return true;
}
}
let videoElements = this.browser.contentDocument.getElementsByTagName("video");
for each (let video in videoElements) {
if (video.paused == inactive && video.duration > mediaDurationThreshold) {
return true;
}
}
return false;
},
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "before-first-paint":
@ -4409,20 +4432,27 @@ Tab.prototype = {
}
let winId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
if (this.browser.outerWindowID == winId) {
let status;
if (aTopic == "media-playback") {
status = aData === "active" ? "start" : "end";
} else if (aTopic == "media-playback-resumed") {
status = "resume";
}
Messaging.sendRequest({
type: "Tab:MediaPlaybackChange",
tabID: this.id,
status: status
});
if (this.browser.outerWindowID != winId) {
return;
}
let isInactive = (aData === "inactive");
if (!this.ShouldNotifyMediaPlaybackChange(isInactive)) {
return;
}
let status;
if (aTopic == "media-playback") {
status = isInactive ? "end" : "start";
} else if (aTopic == "media-playback-resumed") {
status = "resume";
}
Messaging.sendRequest({
type: "Tab:MediaPlaybackChange",
tabID: this.id,
status: status
});
break;
}
},