Skip to content

Commit

Permalink
Add pause/stop support
Browse files Browse the repository at this point in the history
  • Loading branch information
anantn committed Oct 29, 2012
1 parent 2f4da79 commit f734461
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion constraints_test.html
Expand Up @@ -50,7 +50,7 @@ <h1>Simple PeerConnection Constraints Test</h1>
// pc2.setRemote finished, call pc2.createAnswer
function step3() {
pc2.createAnswer(step4, failed, {
optional: [
"optional": [
{"OfferToReceiveAudio": true},
{"OfferToReceiveVideo": true}
]
Expand Down
36 changes: 30 additions & 6 deletions gum_test.html
Expand Up @@ -50,13 +50,13 @@ <h1><b>gUM Test Page</b></h1>
</div>
<div id="content"></div>
<div id="message"></div>
<div id="stopbuttons">
<div style="display: none;" id="stopbuttons">
<input value="Stop" onclick="stopMedia();" type="button">
<input value="Pause/Play" onclick="pauseMedia();" type="button">
</div>

</div>

<script type="application/javascript">
<script type="application/javascript">
var video_status = false;
var video = document.createElement("video");
video.setAttribute("width", 800);
Expand All @@ -75,7 +75,7 @@ <h1><b>gUM Test Page</b></h1>
var message = document.getElementById("message");
var content = document.getElementById("content");

var reader = new FileReader();
var saved_stream = null;

function startVideo() {
video_status = true;
Expand All @@ -100,12 +100,12 @@ <h1><b>gUM Test Page</b></h1>

function stopMedia() {
if (video_status) {
video.pause();
video.mozSrcObject.stop();
video.mozSrcObject = null;
content.removeChild(video);
video_status = false;
} else if (audio_status) {
audio.pause();
audio.mozSrcObject.stop();
audio.mozSrcObject = null;
content.removeChild(audio);
audio_status = false;
Expand All @@ -114,10 +114,34 @@ <h1><b>gUM Test Page</b></h1>
content.removeChild(picture);
picture_status = false;
}
saved_stream = null;
stop.style.display = "none";
start.style.display = "block";
}

function pauseMedia() {
if (saved_stream) {
if (video_status) {
video.mozSrcObject = saved_stream;
video.play();
} else if (audio_status) {
audio.mozSrcObject = saved_stream;
audio.play();
}
saved_stream = null;
} else {
if (video_status) {
video.pause();
saved_stream = video.mozSrcObject;
video.mozSrcObject = null;
} else if (audio_status) {
audio.pause();
saved_stream = audio.mozSrcObject;
audio.mozSrcObject = null;
}
}
}

function startMedia(param) {
stop.style.display = "block";
start.style.display = "none";
Expand Down

0 comments on commit f734461

Please sign in to comment.