summaryrefslogtreecommitdiff
path: root/js/utils.js
blob: 33d050091ef04a647a1d599b65d70883fd909b64 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
 * @module MultimediaPlayerApplication
 */

/**
 * Utility class with helper methods for Multimedia player.
 *
 * @class Utils
 */
var Utils = {
	/**
	 * Provides default thumbnails for given media types.
	 *
	 * @method getDefaultThumbnailByType
	 * @param type {String} media type
	 */
	getDefaultThumbnailByType : function(type) {
		"use strict";
		var thumbnail = "";
		switch (type) {
		case "AUDIO":
			thumbnail = "/images/audio-placeholder.jpg";
			break;
		case "VIDEO":
			thumbnail = "/images/video-placeholder.jpg";
			break;
		case "CONTAINER":
			thumbnail = "/images/container-placeholder.jpg";
			break;
		default:
			thumbnail = "/images/default-placeholder.jpg";
			break;
		}
		return thumbnail;
	},
	/**
	 * Gets thumbnail path out of media item object if exists otherwise gets default placeholder by type.
	 *
	 * @method getThumbnailPath
	 * @param mediaItem {Object}  media item object
	 * @param type {String} media type
	 * @return {String} thumbnail path
	 */
	getThumbnailPath : function(mediaItem, type) {
		"use strict";
		if (!!mediaItem) {
			if (!!mediaItem.thumbnailURIs && mediaItem.thumbnailURIs.length) {
				return mediaItem.thumbnailURIs[0];
			}
			if (!!mediaItem.type) {
				return this.getDefaultThumbnailByType(mediaItem.type);
			}
		}
		return this.getDefaultThumbnailByType(type || "");
	},
	/**
	 * Gets artist's name out of media item object.
	 *
	 * @method getArtistName
	 * @param mediaItem {Object} media item
	 * @return {String} artist name
	 */
	getArtistName : function(mediaItem) {
		"use strict";
		if (!!mediaItem && !!mediaItem.artists && mediaItem.artists.length) {
			return mediaItem.artists.join(", ");
		}
		return "Unknown";
	},
	/**
	 * Gets album name out of media item object.
	 *
	 * @method getAlbumName
	 * @param mediaItem {Object} media item
	 * @return {String} album name
	 */
	getAlbumName : function(mediaItem) {
		"use strict";
		if (!!mediaItem && !!mediaItem.album && mediaItem.album !== "") {
			return mediaItem.album;
		}
		return "Unknown";
	},
	/**
	 * Gets media item title out of media item object.
	 *
	 * @method getMediaItemTitle
	 * @param mediaItem {Object} media item
	 * @return {String} media title
	 */
	getMediaItemTitle : function(mediaItem) {
		"use strict";
		if (!!mediaItem && !!mediaItem.title && mediaItem.title !== "") {
			return mediaItem.title;
		}
		if (!!mediaItem && !!mediaItem.name && mediaItem.name !== "") {
			return mediaItem.name;
		}
		return "Unknown";
	},
	/**
	 * Calls fullscreen request for given html element.
	 *
	 * @method launchFullScreen
	 * @param element {Object}
	 */
	launchFullScreen : function(element) {
		"use strict";
		console.log("Launching full screen");
		if (element.requestFullScreen) {
			element.requestFullScreen();
		} else if (element.mozRequestFullScreen) {
			element.mozRequestFullScreen();
		} else if (element.webkitRequestFullScreen) {
			element.webkitRequestFullScreen();
		}
	}
};