1 //Logging for QT |
1 //Logging for QT |
2 |
2 |
3 // Override the default alert function. |
3 // Override the default alert function. |
|
4 // TODO remove this when alert in platform is working? |
4 alert = function(str) { |
5 alert = function(str) { |
5 console.log(str); |
6 console.log(str); |
6 if(window['context'] && context['owner']){ |
|
7 context.owner().debugJs('alert: ' + str); |
|
8 } |
|
9 window.context.owner().errorHandler("Alert", str); |
7 window.context.owner().errorHandler("Alert", str); |
10 } |
8 } |
11 |
9 |
12 function logme(str){ |
10 function logme(str){ |
13 console.log(str); |
11 console.log(str); |
36 |
34 |
37 window["music"] = window["music"] || |
35 window["music"] = window["music"] || |
38 {}; |
36 {}; |
39 |
37 |
40 (function(){ |
38 (function(){ |
41 if (typeof window.context === 'undefined') { |
|
42 window['context'] = { |
|
43 token: "hipsu:hipsupass", |
|
44 song: "Queen - Bohemian Rhapsody", |
|
45 objectReservedLength: function(){return 70;}, |
|
46 objectContent: function() { return "http://music.ovi.com/ru/ru/pc/Product/Queen/Bohemian-Rhapsody/8019069"; }, |
|
47 objectType: function(){ return "URI"; }, |
|
48 artist: function() { return "♫ Queen"; }, |
|
49 title: function() { return "Bohemian Rhapsody"; }, |
|
50 username: function() { return "hipsu"; }, |
|
51 password: function() { return "hipsupass"; }, |
|
52 albumArtBase64: function() { return "https://secure-profile.facebook.com/v227/1739/21/n100000756794479_1863.jpg"; }, |
|
53 owner: function() { |
|
54 return { |
|
55 errorHandler: function(a,b) {}, |
|
56 clearCache: function() {}, |
|
57 debugJs: function(s) {} |
|
58 } |
|
59 } |
|
60 } |
|
61 }else{ |
|
62 try { |
|
63 logme(context.objectType() + ' | ' + window.context.objectContent() + ' | ' + window.context.objectReservedLength()); |
|
64 }catch (e) { |
|
65 logme(e); |
|
66 } |
|
67 } |
|
68 |
|
69 var musicContext = null; |
39 var musicContext = null; |
70 var publishingPlayer = null; |
40 var publishingPlayer = null; |
71 |
41 |
72 music.getPostContent = function(){ |
42 music.getPostContent = function(){ |
73 traceme(); |
43 traceme(); |
76 type : window.context.objectType(), |
46 type : window.context.objectType(), |
77 content : window.context.objectContent() |
47 content : window.context.objectContent() |
78 }; |
48 }; |
79 } |
49 } |
80 |
50 |
81 // Hard code something for the browser.. |
|
82 |
|
83 /** |
|
84 * Check if player is loaded and call error function if not. |
|
85 */ |
|
86 music.playerLoaded = function() { |
|
87 traceme(); |
|
88 if (!_playerReady()) { |
|
89 alert("Error loading player scripts"); |
|
90 } |
|
91 } |
|
92 |
|
93 /** |
51 /** |
94 * Call this for player to show UI and initialize connection to SNC |
52 * Call this for player to show UI and initialize connection to SNC |
95 */ |
53 */ |
96 music.initPlayer = function() |
54 music.initPlayer = function() |
97 { |
55 { |
98 traceme(); |
56 traceme(); |
99 // Initialize player |
57 // Initialize player |
100 publishingPlayer = new ovi.player.publish.Player({ |
58 publishingPlayer = new ovi.player.publish.Player({ |
101 locale : "en-US", |
59 locale : window.context.language(), |
102 credentials : { |
60 credentials : { |
103 type : "", |
61 type : "", |
104 sso_base_url : "", |
62 sso_base_url : "", |
105 token : _getNoa() |
63 token : _getNoa() |
106 } |
64 } |
109 // Show UI |
67 // Show UI |
110 publishingPlayer.create(null, function(status, data){ |
68 publishingPlayer.create(null, function(status, data){ |
111 traceme(); |
69 traceme(); |
112 if (status != publishingPlayer.status.updateservices_ok && status != publishingPlayer.status.show_ok) { |
70 if (status != publishingPlayer.status.updateservices_ok && status != publishingPlayer.status.show_ok) { |
113 // Delegate errors to native side |
71 // Delegate errors to native side |
114 window.context.errorHandler(status, data.message); |
72 window.context.owner().errorHandler(status, data.message); |
115 } |
73 } |
116 }); |
74 }); |
117 |
75 |
118 } |
76 } |
119 |
77 |
122 */ |
80 */ |
123 music.updateContextArea = function() { |
81 music.updateContextArea = function() { |
124 // Update artist and title metadata. |
82 // Update artist and title metadata. |
125 traceme(); |
83 traceme(); |
126 publishingPlayer.setContextObject(_getMusicContext()); |
84 publishingPlayer.setContextObject(_getMusicContext()); |
127 } |
85 if(window['context'] && context['owner']){ |
|
86 context.owner().showWindow(); |
|
87 } |
|
88 } |
128 |
89 |
129 /** |
90 /** |
130 * Call this function to update metadata (called when music player has retrieved the link) |
91 * Call this function to update metadata (called when music player has retrieved the link) |
131 */ |
92 */ |
132 music.updateMetadata = function() { |
93 music.updateMetadata = function() { |
164 |
125 |
165 var sharePlayerArtImage = ""; |
126 var sharePlayerArtImage = ""; |
166 var sharePlayerArtBase64 = window.context.albumArtBase64(); |
127 var sharePlayerArtBase64 = window.context.albumArtBase64(); |
167 if ( sharePlayerArtBase64.length > 0 ) { |
128 if ( sharePlayerArtBase64.length > 0 ) { |
168 // TODO: this is temporary solution until base64 defect in QT is fixed. |
129 // TODO: this is temporary solution until base64 defect in QT is fixed. |
169 sharePlayerArtImage = "<img class='cover' src='" + sharePlayerArtBase64 + "' width='74px' height='74px' />"; |
130 sharePlayerArtImage = "<td valign='top' width='74px'><img src='" + sharePlayerArtBase64 + "' width='74px' height='74px' /></td>"; |
170 // sharePlayerArtImage = "<img class='cover' src='data:image/png;base64," + sharePlayerArtBase64 + "' width='74px' height='74px' />"; |
131 // sharePlayerArtImage = "<img class='cover' src='data:image/png;base64," + sharePlayerArtBase64 + "' width='74px' height='74px' />"; |
171 } |
132 } |
172 // Create context object |
133 // Create context object |
173 musicContext.create({ |
134 musicContext.create({ |
174 view: "none", |
135 view: "none", |
175 data: { |
136 data: { |
176 miniview: "<ul class='list info-list'>" |
137 miniview: "<table width='100%' class='list info-list'><tr>" |
177 /* |
138 /* |
178 // TODO REMOVE, for testing only |
139 // TODO REMOVE, for testing only |
179 + "<p>username: " + window.context.username() + "/" + window.context.password() + "</p><BR>" |
|
180 + "<input type=\"button\" value=\"Clear JS Cache\" onClick=\"window.context.owner().clearCache();\">" |
140 + "<input type=\"button\" value=\"Clear JS Cache\" onClick=\"window.context.owner().clearCache();\">" |
181 */ |
141 */ |
182 + sharePlayerArtImage |
142 + sharePlayerArtImage |
183 + "<span class='description'><div class='title'>" + window.context.title() + "</div>" |
143 + "<td align='left' valign='top'>" |
184 + "<div class='artist'>" + window.context.artist() + "</div></span>" |
144 + "<span class='description'>" |
185 + "</ul>", |
145 + "<div class='title'>" + window.context.title() + "</div>" |
|
146 + "<div class='artist'>" + window.context.artist() + "</div>" |
|
147 + "</span>" |
|
148 + "</td></tr></table>", |
186 object: attachment |
149 object: attachment |
187 } |
150 } |
188 }); |
151 }); |
189 return musicContext; |
152 return musicContext; |
190 } |
153 } |