Bug 1208371 - Move track.stop() helpers to MediaStreamPlayback. r=jib

MozReview-Commit-ID: 81pu4jvcrRs

--HG--
extra : rebase_source : c48047ac832433f7c162778fba779a556f5612d4
This commit is contained in:
Andreas Pehrson 2016-01-05 10:16:26 +08:00
Родитель ddf091a726
Коммит 378506f7fc
1 изменённых файлов: 43 добавлений и 44 удалений

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

@ -25,6 +25,49 @@ function MediaStreamPlayback(mediaElement, mediaStream) {
MediaStreamPlayback.prototype = {
/**
* Starts media element with a media stream, runs it until a canplaythrough
* and timeupdate event fires, and calls stop() on all its tracks.
*
* @param {Boolean} isResume specifies if this media element is being resumed
* from a previous run
*/
playMediaWithMediaStreamTracksStop : function(isResume) {
this.startMedia(isResume);
return this.verifyPlaying()
.then(() => this.stopTracksForStreamInMediaPlayback())
.then(() => this.stopMediaElement());
},
/**
* Stops the local media stream's tracks while it's currently in playback in
* a media element.
*
* Precondition: The media stream and element should both be actively
* being played. All the stream's tracks must be local.
*/
stopTracksForStreamInMediaPlayback : function () {
var elem = this.mediaElement;
var waitForEnded = () => new Promise(resolve => {
elem.addEventListener('ended', function ended() {
elem.removeEventListener('ended', ended);
resolve();
});
});
// TODO (bug 910249) Also check that all the tracks are local.
this.mediaStream.getTracks().forEach(t => t.stop());
// XXX (bug 1208316) When we implement MediaStream.active, do not stop
// the stream. We just do it now so the media element will raise 'ended'.
if (!this.mediaStream.stop) {
return;
}
this.mediaStream.stop();
return timeout(waitForEnded(), ENDED_TIMEOUT_LENGTH, "ended event never fired")
.then(() => ok(true, "ended event successfully fired"));
},
/**
* Starts media with a media stream, runs it until a canplaythrough and
* timeupdate event fires, and stops the media.
@ -131,50 +174,6 @@ function LocalMediaStreamPlayback(mediaElement, mediaStream) {
LocalMediaStreamPlayback.prototype = Object.create(MediaStreamPlayback.prototype, {
/**
* Starts media element with a media stream, runs it until a canplaythrough
* and timeupdate event fires, and calls stop() on all its tracks.
*
* @param {Boolean} isResume specifies if this media element is being resumed
* from a previous run
*/
playMediaWithMediaStreamTracksStop: {
value: function(isResume) {
this.startMedia(isResume);
return this.verifyPlaying()
.then(() => this.stopTracksForStreamInMediaPlayback())
.then(() => this.stopMediaElement());
}
},
/**
* Stops the local media stream's tracks while it's currently in playback in
* a media element.
*
* Precondition: The media stream and element should both be actively
* being played. All the stream's tracks must be local.
*/
stopTracksForStreamInMediaPlayback: {
value: function () {
var elem = this.mediaElement;
var waitForEnded = () => new Promise(resolve => {
elem.addEventListener('ended', function ended() {
elem.removeEventListener('ended', ended);
resolve();
});
});
// TODO (bug 910249) Also check that all the tracks are local.
this.mediaStream.getTracks().forEach(t => t.stop());
// XXX (bug 1208316) When we implement MediaStream.active, do not stop
// the stream. We just do it now so the media element will raise 'ended'.
this.mediaStream.stop();
return timeout(waitForEnded(), ENDED_TIMEOUT_LENGTH, "ended event never fired")
.then(() => ok(true, "ended event successfully fired"));
}
},
/**
* DEPRECATED - MediaStream.stop() is going away. Use MediaStreamTrack.stop()!
*