summaryrefslogtreecommitdiffstats
path: root/mobile/android/tests/browser/robocop/robocop_getusermedia.html
blob: 1ec86d61bfff8f015d049e69268930e7602abc0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html><head>
  <title>gUM Test Page</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" charset="utf-8">
</head>
<body>
  <div id="content"></div>
  <script type="application/javascript">
  var video_status = false;
  var video = document.createElement("video");
  video.setAttribute("width", 640);
  video.setAttribute("height", 480);

  var audio_status = false;
  var audio = document.createElement("audio");
  audio.setAttribute("controls", true);

  var content = document.getElementById("content");
  document.title = "gUM Test Page";

  startAudioVideo();

  function startAudioVideo() {
    video_status = true;
    audio_status = true;
    mediaConstraints = {
      video: {
        mozMediaSource: "browser",
        mediaSource: "browser"
      },
      audio: true
    };
    startMedia(mediaConstraints);
  }

  function stopMedia() {
    if (video_status) {
      video.srcObject.stop();
      video.srcObject = null;
      content.removeChild(video);
      capturing = false;
      video_status = false;
    }
    if (audio_status) {
      audio.srcObject.stop();
      audio.srcObject = null;
      content.removeChild(audio);
      audio_status = false;
    }
  }

  function startMedia(param) {
    try {
      window.navigator.mozGetUserMedia(param, function(stream) {
        if (video_status) {
          content.appendChild(video);
          video.srcObject = stream;
          video.play();
        }
        if (audio_status) {
          content.appendChild(audio);
          audio.srcObject = stream;
          audio.play();
        }
        var audioTracks = stream.getAudioTracks();
        var videoTracks = stream.getVideoTracks();
        document.title = "";
        if (audioTracks.length > 0) {
          document.title += "audio";
        }
        if (videoTracks.length > 0) {
          document.title += "video";
        }
        document.title += " gumtest";
        audio.srcObject.stop();
        video.srcObject.stop();
      }, function(err) {
        document.title = "failed gumtest";
        stopMedia();
      });
    } catch(e) {
      stopMedia();
    }
  }
</script>
</body></html>