Updated GhostCluster web sample from upstream
[profile/ivi/sdk/web-sample-build.git] / samples / web / Sample / Tizen / Web App / ModelloMultimediaPlayer / project / js / mediacontent.js
1 /******************************************************************************
2  * Copyright 2012 Intel Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16
17 /**
18  * @module MultimediaPlayerApplication
19  */
20
21 /**
22  * Class providing objects mapping the org.gnome.UPnP MediaObject2 and MediaItem2 interfaces.
23  *
24  * @class mediacontent
25  */
26 var mediacontent = window.mediacontent = {};
27
28 /**
29  * Generic media object.
30  *
31  * @class MediaObject
32  * @return {Object} MediaObject objects
33  */
34 mediacontent.MediaObject = function(proxy) {
35         "use strict";
36         this.proxy = proxy;
37         if (proxy) {
38                 this.id = proxy.Path;
39                 this.type = proxy.Type;
40                 this.title = proxy.DisplayName;
41         }
42         return this;
43 };
44
45 /**
46  * Gets the MediaObject metadata info.
47  *
48  * @method getMetaData
49  * @return {Object} metadata object
50  */
51 mediacontent.MediaObject.prototype.getMetaData = function() {
52         "use strict";
53         return this.proxy.callMethod("org.gnome.UPnP.MediaObject2", "GetMetaData", []);
54 };
55
56 /**
57  * Mediacontent object of type container.
58  *
59  * @class MediaContainer
60  * @param proxy {Object} media source object
61  * @return {Object} MediaContainer object
62  */
63 mediacontent.MediaContainer = function(proxy) {
64         "use strict";
65         mediacontent.MediaObject.call(this, proxy);
66         this.type = "CONTAINER";
67         this.directoryURI = "";
68         this.storageType = "EXTERNAL";
69         this.title = proxy.title;
70         if (this.id === undefined)
71                 this.id = proxy.id;
72
73         return this;
74 };
75
76 mediacontent.MediaContainer.prototype = new mediacontent.MediaObject();
77 mediacontent.MediaContainer.prototype.constructor = mediacontent.MediaContainer;
78
79 /**
80  * Mediacontent object of type media item. Provides access to properties of media items.
81  *
82  * @class MediaItem
83  * @param proxy {Object} media source object
84  * @return {Object} MediaItem object
85  */
86 mediacontent.MediaItem = function(proxy) {
87         "use strict";
88         mediacontent.MediaObject.call(this, proxy);
89         if (proxy) {
90                 this.mimeType = proxy.mimeType;
91                 if (proxy.URLs) {
92                         this.contentURI = proxy.URLs[0];
93                 } else {
94                         this.contentURI = proxy.sourceUri;
95                 }
96                 this.size = proxy.fileSize;
97                 this.releaseDate = proxy.createDate;
98                 this.modifiedDate = null;
99                 this.name = proxy.title;
100                 this.title = proxy.title;
101                 this.editableAttributes = [];
102                 this.thumbnailURIs = [];
103                 if (!!proxy.AlbumArtURL && proxy.AlbumArtURL !== "") {
104                         this.thumbnailURIs.push(proxy.AlbumArtURL);
105                 }
106                 this.description = "Unknown";
107                 this.rating = 0;
108         }
109         this.type = "OTHER";
110         return this;
111 };
112
113 mediacontent.MediaItem.prototype = new mediacontent.MediaObject();
114 mediacontent.MediaItem.prototype.constructor = mediacontent.MediaItem;
115
116 /**
117  * Mediacontent object of type video. Extends a basic media item object with video-specific attributes.
118  *
119  * @class MediaVideo
120  * @param proxy {Object} media source object
121  * @return {Object} MediaVideo object
122  */
123 mediacontent.MediaVideo = function(proxy) {
124         "use strict";
125         mediacontent.MediaItem.call(this, proxy);
126         if (proxy) {
127                 this.duration = proxy.duration * 1000; //Tizen's ContentVideo is in ms
128                 this.width = proxy.width;
129                 this.height = proxy.height;
130                 if (proxy.Album) {
131                         this.album = proxy.Album;
132                 }
133                 else if (proxy.collection) {
134                         this.album = proxy.collection;
135                 }
136                 else {
137                         this.album = "Unknown";
138                 }
139
140                 if (proxy.Artist) {
141                         this.artists = [ proxy.Artist ];
142                 }
143                 else if (proxy.author) {
144                         this.artists = [ proxy.author ];
145                 }
146                 else {
147                         this.artists = [ "Unknown" ];
148                 }
149                 this.geolocation = null;
150         }
151         this.type = "VIDEO";
152         return this;
153 };
154
155 mediacontent.MediaVideo.prototype = new mediacontent.MediaItem();
156 mediacontent.MediaVideo.prototype.constructor = mediacontent.MediaVideo;
157
158 /**
159  * Mediacontent object of type audio. Extends a basic media item object with audio-specific attributes.
160  *
161  * @class MediaAudio
162  * @param proxy {Object} media source object
163  * @return {Object} MediaAudio object
164  */
165 mediacontent.MediaAudio = function(proxy) {
166         "use strict";
167         mediacontent.MediaItem.call(this, proxy);
168         if (proxy) {
169                 this.bitrate = proxy.audioSampleRate;
170                 this.duration = proxy.duration * 1000; //Tizen's ContentAudio is in ms
171                 if (proxy.Album) {
172                         this.album = proxy.Album;
173                 } else {
174                         this.album = "Unknown";
175                 }
176                 if (proxy.Artist) {
177                         this.artists = [ proxy.Artist ];
178                 }
179                 else if (proxy.author) {
180                         this.artists = [ proxy.author ];
181                 } else {
182                         this.artists = [ "Unknown" ];
183                 }
184                 this.genres = [];
185                 this.composers = [ "Unknown" ];
186                 this.lyrics = null;
187                 this.copyright = "Unknown";
188                 if (proxy.trackNumber)
189                         this.trackNumber = proxy.trackNumber;
190                 else
191                         this.trackNumber = 0;
192         }
193         this.type = "AUDIO";
194         return this;
195 };
196
197 mediacontent.MediaAudio.prototype = new mediacontent.MediaItem();
198 mediacontent.MediaAudio.prototype.constructor = mediacontent.MediaAudio;
199
200 /**
201  * Mediacontent object of type image. Extends a basic media item object with image-specific attributes.
202  *
203  * @class MediaImage
204  * @param proxy {Object} media source object
205  * @return {Object} MediaImage object
206  */
207 mediacontent.MediaImage = function(proxy) {
208         "use strict";
209         mediacontent.MediaItem.call(this, proxy);
210         if (proxy) {
211                 this.width = proxy.width;
212                 this.height = proxy.height;
213                 this.orientation = "NORMAL";
214         }
215         this.type = "IMAGE";
216         return this;
217 };
218
219 mediacontent.MediaImage.prototype = new mediacontent.MediaItem();
220 mediacontent.MediaImage.prototype.constructor = mediacontent.MediaImage;
221
222 /**
223  * Returns appropriate media object based on the given parameter media type.
224  *
225  * @class mediaObjectForProps
226  * @param props {Object} media source object
227  * @return {Object} correct media object by props.type
228  */
229 mediacontent.mediaObjectForProps = function(props) {
230         "use strict";
231
232         if (props.type.indexOf("container") === 0 || props.type.indexOf("album") === 0 || props.type.indexOf("person") === 0 || props.type.indexOf("genre") === 0){
233                 return new mediacontent.MediaContainer(props);
234         }
235         if (props.type.indexOf("video") === 0){
236                 return new mediacontent.MediaVideo(props);
237         }
238         if (props.type.indexOf("audio") === 0 || props.type.indexOf("music") === 0){
239                 return new mediacontent.MediaAudio(props);
240         }
241         if (props.type.indexOf("image") === 0 || props.type.indexOf("picture") === 0) {
242                 return new mediacontent.MediaImage(props);
243         }
244
245         return new mediacontent.MediaItem(props);
246 };