~ubuntu-branches/ubuntu/vivid/unity-webapps-qml/vivid

« back to all changes in this revision

Viewing changes to tests/autopilot/html/test_webapps_mediaplayer.html

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Alexandre Abreu
  • Date: 2014-07-18 17:40:27 UTC
  • mfrom: (1.1.35)
  • Revision ID: package-import@ubuntu.com-20140718174027-ib7s8vyk5gzpla4u
Tags: 0.1+14.10.20140718.1-0ubuntu1
[ Alexandre Abreu ]
Add bidirectional callback support between js <-> qml,

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
 
 
3
<head>
 
4
<title>Unity Webapps QML test: MediaPlayer</title>
 
5
 
 
6
<script>
 
7
 
 
8
var MEDIAPLAYER_STATE_PLAYING = 0;
 
9
var MEDIAPLAYER_STATE_PAUSED = 1;
 
10
 
 
11
var unity;
 
12
function onInit() {
 
13
  unity.MediaPlayer.setCanGoNext(true);
 
14
  unity.MediaPlayer.setCanGoPrevious(true);
 
15
  unity.MediaPlayer.setCanPlay(true);
 
16
  unity.MediaPlayer.setPlaybackState(MEDIAPLAYER_STATE_PAUSED);
 
17
 
 
18
  unity.MediaPlayer.setTrack({ album: "MyAlbum", title: "MyTitle", artist: "MyArtist" });
 
19
 
 
20
  document.getElementById('status').innerHTML = 'mediaplayer-updated';
 
21
}
 
22
 
 
23
document.addEventListener('ubuntu-webapps-api-ready', function () {
 
24
  console.log('ubuntu-webapps-api-ready received');
 
25
 
 
26
  unity = window.external.getUnityObject('1.0');
 
27
 
 
28
  unity.init({name: 'unity-webapps-qml-', domain: 'launcher', onInit: onInit, iconUrl: 'icon://myicon'});
 
29
}, false);
 
30
 
 
31
function dispatchApiCall (target, name, args) {
 
32
  var names = name.split('.');
 
33
  names.reduce (
 
34
    function (prev, cur) {
 
35
        return (typeof prev[cur] == "function") ? (function(prev, cur) { return prev[cur].bind(prev); })(prev, cur) : prev[cur];
 
36
    }, target).apply (null, args);
 
37
};
 
38
 
 
39
document.addEventListener('unity-webapps-do-call', function(e) {
 
40
  var action = JSON.parse(e.detail);
 
41
  var callback = null;
 
42
  if (action.with_callback) {
 
43
    callback = function (response) {
 
44
      var e = new CustomEvent ("unity-webapps-do-call-response", {"detail": response});
 
45
      document.dispatchEvent (e);
 
46
    };
 
47
    action.args.push(callback);
 
48
  }
 
49
  dispatchApiCall(unity, action.name, action.args);
 
50
}, false);
 
51
 
 
52
</script>
 
53
 
 
54
</head>
 
55
 
 
56
<body>
 
57
 
 
58
HELLO WORLD
 
59
 
 
60
<div id="content">
 
61
  <h1>THE CONTENT IS VISIBLE</h1>
 
62
</div>
 
63
 
 
64
<!-- Used as a communication status (to avoid races) between the app & the test -->
 
65
<div id="status"></div>
 
66
 
 
67
</body>
 
68
 
 
69
</html>