1 //Logging for QT |
|
2 |
|
3 // Override the default alert function. |
|
4 // TODO remove this when alert in platform is working? |
|
5 alert = function(str) { |
|
6 console.log(str); |
|
7 window.context.owner().errorHandler("Alert", str); |
|
8 } |
|
9 |
|
10 function logme(str){ |
|
11 console.log(str); |
|
12 if(window['context'] && context['owner']){ |
|
13 context.owner().debugJs('debugJs: ' + str); |
|
14 } |
|
15 } |
|
16 |
|
17 function traceme(){ |
|
18 var cf = arguments.callee.caller; |
|
19 logme('-------------- Start traceme ' + new Date().toLocaleTimeString() + ' --------------'); |
|
20 var arr = new Array(); |
|
21 while (cf) { |
|
22 var fn = cf.toString(); |
|
23 fn = fn.substr(0,fn.indexOf('{')); |
|
24 arr.push(fn); |
|
25 cf = cf.caller; |
|
26 } |
|
27 //arr.reverse(); |
|
28 for(i=0;i<=arr.length -1;i++){ |
|
29 logme(arr[i]); |
|
30 } |
|
31 logme('-------------- End traceme --------------'); |
|
32 } |
|
33 |
|
34 |
|
35 window["music"] = window["music"] || |
|
36 {}; |
|
37 |
|
38 (function(){ |
|
39 var musicContext = null; |
|
40 var publishingPlayer = null; |
|
41 |
|
42 music.getPostContent = function(){ |
|
43 traceme(); |
|
44 return { |
|
45 reservedLength : window.context.objectReservedLength(), |
|
46 type : window.context.objectType(), |
|
47 content : window.context.objectContent() |
|
48 }; |
|
49 } |
|
50 |
|
51 /** |
|
52 * Call this for player to show UI and initialize connection to SNC |
|
53 */ |
|
54 music.initPlayer = function() |
|
55 { |
|
56 traceme(); |
|
57 // Initialize player |
|
58 publishingPlayer = new ovi.player.publish.Player({ |
|
59 locale : window.context.language(), |
|
60 credentials : { |
|
61 type : "", |
|
62 sso_base_url : "", |
|
63 token : _getNoa() |
|
64 } |
|
65 }); |
|
66 |
|
67 // Show UI |
|
68 publishingPlayer.create(null, function(status, data){ |
|
69 traceme(); |
|
70 if (status != publishingPlayer.status.updateservices_ok && status != publishingPlayer.status.show_ok) { |
|
71 // Delegate errors to native side |
|
72 window.context.owner().errorHandler(status, data.message); |
|
73 } |
|
74 }); |
|
75 |
|
76 } |
|
77 |
|
78 /** |
|
79 * Call this for player to update context area (the song UI). |
|
80 */ |
|
81 music.updateContextArea = function() { |
|
82 // Update artist and title metadata. |
|
83 traceme(); |
|
84 publishingPlayer.setContextObject(_getMusicContext()); |
|
85 if(window['context'] && context['owner']){ |
|
86 context.owner().showWindow(); |
|
87 } |
|
88 } |
|
89 |
|
90 /** |
|
91 * Call this function to update metadata (called when music player has retrieved the link) |
|
92 */ |
|
93 music.updateMetadata = function() { |
|
94 // Update url at bottom of comment field. |
|
95 traceme(); |
|
96 musicContext.updateObject(music.getPostContent()); |
|
97 } |
|
98 |
|
99 /** |
|
100 * Call this function to release all resources from player. |
|
101 */ |
|
102 music.teardown = function() { |
|
103 traceme(); |
|
104 publishingPlayer.cancel(); |
|
105 } |
|
106 |
|
107 // Private functions, read data from native side.. |
|
108 function _playerReady() { |
|
109 traceme(); |
|
110 return typeof ovi != "undefined" && |
|
111 typeof ovi.player != "undefined" && |
|
112 typeof ovi.player.publish != "undefinded"; |
|
113 } |
|
114 |
|
115 |
|
116 function _getMusicContext() { |
|
117 traceme(); |
|
118 musicContext = new ovi.player.contextobject.Player(); |
|
119 |
|
120 var attachment = music.getPostContent(); |
|
121 |
|
122 logme('music._getMusicContext() | attachment'); |
|
123 |
|
124 logme('music._getMusicContext() | musicContext.create'); |
|
125 |
|
126 var sharePlayerArtImage = ""; |
|
127 var sharePlayerArtBase64 = window.context.albumArtBase64(); |
|
128 if ( sharePlayerArtBase64.length > 0 ) { |
|
129 // TODO: this is temporary solution until base64 defect in QT is fixed. |
|
130 sharePlayerArtImage = "<td valign='top' width='74px'><img src='" + sharePlayerArtBase64 + "' width='74px' height='74px' /></td>"; |
|
131 // sharePlayerArtImage = "<img class='cover' src='data:image/png;base64," + sharePlayerArtBase64 + "' width='74px' height='74px' />"; |
|
132 } |
|
133 // Create context object |
|
134 musicContext.create({ |
|
135 view: "none", |
|
136 data: { |
|
137 miniview: "<table width='100%' class='list info-list'><tr>" |
|
138 /* |
|
139 // TODO REMOVE, for testing only |
|
140 + "<input type=\"button\" value=\"Clear JS Cache\" onClick=\"window.context.owner().clearCache();\">" |
|
141 */ |
|
142 + sharePlayerArtImage |
|
143 + "<td align='left' valign='top'>" |
|
144 + "<span class='description'>" |
|
145 + "<div class='title'>" + window.context.title() + "</div>" |
|
146 + "<div class='artist'>" + window.context.artist() + "</div>" |
|
147 + "</span>" |
|
148 + "</td></tr></table>", |
|
149 object: attachment |
|
150 } |
|
151 }); |
|
152 return musicContext; |
|
153 } |
|
154 |
|
155 function _getNoa() { |
|
156 traceme(); |
|
157 // temporary solution until SSO token get from QT SSO DE (now we fetch username, password and re-authenticate using api.ovi.com) |
|
158 var token = (window.context.username)? [window.context.username(),window.context.password()] : window.context.token.split(":"); |
|
159 logme(token[0] + "/" + token[1]); |
|
160 return { |
|
161 username: token[0], |
|
162 password: token[1] |
|
163 } |
|
164 } |
|
165 })(); |
|