*
*/
+var mainArtistText;
+var songDurationSec;
+
AudioPlayer = function()
{
this.clearAudioTimeInterval = undefined;
this.currentAudioContent = undefined;
}
+/*
+ * Play function for when play button is clicked
+ */
+
AudioPlayer.prototype.play = function()
{
console.log("MediaPlayer in AudioPlayer::play");
var timeoutFunction = function()
{
localStorage.prevAudioTime = this.playerControls.currentTime;
+ this.updateTrackTime();
}
this.clearAudioTimeInterval = setInterval(timeoutFunction.bind(this),500);
console.log(this.content[this.listIndex].artists[0] + " : " + this.content[this.listIndex].title + " can't play yet, it hasn't loaded");
}
+/*
+ * Pause function for when pause button is clicked
+ */
+
AudioPlayer.prototype.pause = function()
{
if (!this.playerControls.paused)
}
}
-AudioPlayer.prototype.playing = function()
-{
- return !(this.playerControls.paused);
-}
+/*
+ * Next function for when next button is clicked
+ */
AudioPlayer.prototype.next = function()
{
}
}
+/*
+ * Previous function for when previous button is clicked
+ */
+
AudioPlayer.prototype.previous = function()
{
if (this.content)
}
}
+/*
+ * Returns play state
+ */
+
+AudioPlayer.prototype.playing = function()
+{
+ return !(this.playerControls.paused);
+}
+
+/*
+ * Load the file located at the index. If play is true, play immediately once file is loaded
+ */
+
AudioPlayer.prototype.load = function(index, play)
{
this.listIndex = index;
this.playerControls.load();
}
+/*
+ * Redraws the media bar with the new artist, title, and cover album
+ */
+
AudioPlayer.prototype.updateMediaName = function(newArtist, newTitle, newCover)
{
- var playBarHeight = mediaNameCanvas.height;
- var boxWidth = playBarHeight * 0.75;
+ playBarHeight = mediaNameCanvas.height;
+ boxWidth = playBarHeight * 0.75;
+ textStartX = boxWidth + 50;
+ songDurationSec = this.playerControls.duration;
mediaNameCTX.clearRect(0,0,mediaNameCanvas.width, mediaNameCanvas.height);
- var shadeJump = 10;
- var alphaJump = 0.01;
- var currColor = 255;
- var currAlpha = 1.0;
-
mediaNameCTX.fillStyle="rgba(30,30,30,0.5)";
mediaNameCTX.strokeStyle="rgba(130,130,130,1)";
mediaNameCTX.lineWidth = 5;
if (screenOrientation === "portrait")
{
- var textStartX = boxWidth + 50;
-
var trackText = new TextObject(mediaNameCTX,{"text" : newTitle, "xLoc" : textStartX, "yLoc" : 70 , "zLoc" : 0,
"width" : mediaNameCanvas.width - textStartX, "height" : 50, "lineHeight" : 65, "wordWrap" : true});
trackText.applyTemplate(mainMenuTitleTemplate);
- var artistText = new TextObject(mediaNameCTX,{"text" : newArtist, "xLoc" : textStartX, "yLoc" : 70, "zLoc" : 0,
+ mainArtistText = new TextObject(mediaNameCTX,{"text" : newArtist, "xLoc" : textStartX, "yLoc" : 70, "zLoc" : 0,
"width" : mediaNameCanvas.width - textStartX, "height" : 50, "lineHeight" : 50, "wordWrap" : true});
- artistText.applyTemplate(mainTrackTemplate);
+ mainArtistText.applyTemplate(mainTrackTemplate);
}
else
{
- var textStartX = boxWidth + 50;
var trackText = new TextObject(mediaNameCTX,{"text" : newTitle, "xLoc" : textStartX, "yLoc" : 50 , "zLoc" : 0,
"width" : mediaNameCanvas.width - textStartX, "height" : 30, "lineHeight" : 30, "wordWrap" : true});
trackText.applyTemplate(mainMenuTitleTemplateLandscape);
- var artistText = new TextObject(mediaNameCTX,{"text" : newArtist, "xLoc" : textStartX, "yLoc" : 50, "zLoc" : 0,
+ mainArtistText = new TextObject(mediaNameCTX,{"text" : newArtist, "xLoc" : textStartX, "yLoc" : 50, "zLoc" : 0,
"width" : mediaNameCanvas.width - textStartX, "height" : 30, "lineHeight" : 30, "wordWrap" : true});
- artistText.applyTemplate(mainTrackTemplateLandscape);
+ mainArtistText.applyTemplate(mainTrackTemplateLandscape);
}
trackText.drawObj();
trackText.drawLargeShadow();
- artistText.yLoc += trackText.height;
- artistText.drawObj();
+ mainArtistText.yLoc += trackText.height;
+ mainArtistText.drawObj();
+
+ this.updateTrackTime();
}
+/*
+ * Redraws the current track time
+ */
+
+AudioPlayer.prototype.updateTrackTime = function()
+{
+ playBarHeight = mediaNameCanvas.height;
+ boxWidth = playBarHeight * 0.75;
+ textStartX = boxWidth + 50;
+ var timeText = '';
+ var songDurationSec = Math.floor(this.playerControls.duration % 60) > 9 ? Math.floor(this.playerControls.duration % 60) : '0' + Math.floor(this.playerControls.duration % 60);
+ var songDurationMin = Math.floor(this.playerControls.duration / 60) > 9 ? Math.floor(this.playerControls.duration / 60) : '0' + Math.floor(this.playerControls.duration / 60);
+ var songCurrentMin = Math.floor(this.playerControls.currentTime / 60) > 9 ? Math.floor(this.playerControls.currentTime / 60) : '0' + Math.floor(this.playerControls.currentTime / 60);
+ var songCurrentSec = Math.floor(this.playerControls.currentTime % 60) > 9 ? Math.floor(this.playerControls.currentTime % 60) : '0' + Math.floor(this.playerControls.currentTime % 60);
+
+ if ((songCurrentMin !== undefined && songCurrentSec !== undefined) && (!isNaN(songCurrentMin) && !isNaN(songCurrentSec)))
+ timeText += songCurrentMin + ':' + songCurrentSec + ' / ';
+ else
+ timeText += "00:00 / ";
+
+ if ((songDurationSec !== undefined && songDurationMin !== undefined) && (!isNaN(songDurationMin) && !isNaN(songDurationSec)))
+ timeText += songDurationMin + ':' + songDurationSec;
+ else
+ timeText += "00:00";
+
+
+ var trackTimeText = new TextObject(trackTimeCTX,{"text" : timeText, "xLoc" : textStartX, "yLoc" : 50, "zLoc" : 0,
+ "width" : mediaNameCanvas.width - textStartX, "height" : 20, "lineHeight" : 20, "wordWrap" : false});
+
+ trackTimeText.applyTemplate(timeTemplate);
+ trackTimeCTX.clearRect(0, 0, trackTimeCanvas.width, trackTimeCanvas.height);
+
+ trackTimeText.yLoc = ((playBarHeight - boxWidth) / 2) + boxWidth;
+ trackTimeText.drawObj();
+}
+
+/*
+ * Plays the currently loaded media file
+ */
+
AudioPlayer.prototype.playLoadedMedia = function()
{
console.log("MediaPlayer in playLoadedMedia");
this.currentFileLoaded = true;
}
+/*
+ * Sort the file list alphabetically
+ */
AudioPlayer.prototype.sortByAlpha = function()
{
this.fillMediaList();
}
+/*
+ * Sort the file list by artist name
+ */
+
AudioPlayer.prototype.sortByArtist = function()
{
console.log("MediaPlayer in sortByArtist");
this.fillMediaList();
}
+/*
+ * Sort the file list by album name
+ */
+
AudioPlayer.prototype.sortByAlbum =function()
{
console.log("MediaPlayer in sortByAlbum");
this.fillMediaList();
}
+/*
+ * Callback for when the local content has been successfully read using tizen.content.
+ */
+
AudioPlayer.prototype.onContentLoaded = function()
{
try
}
}
-AudioPlayer.prototype.redrawMediaName = function()
-{
- this.updateMediaName(this.content[this.listIndex].artists[0], this.content[this.listIndex].title, this.content[this.listIndex].coverArt);
-}
+/*
+ * Create and draw an item in the media list
+ */
AudioPlayer.prototype.makeListItem = function(j, k)
{
for (var i = j; (i < (j+k) && i < this.content.length); i++)
{
+ if (typeof this.content[i].title !== "string")
+ this.content[i].title = "Unknown";
+
//Check if album art is done loading, if not draw default until it is
if (this.content[i].artists === undefined)
{
this.content[i].artists[0] = "Unknown";
}
- var trackText = {"text" : this.content[i].title, "xLoc" : canvasH + 20, "yLoc" : canvasH / 2.5 , "zLoc" : 0};
- var artistText = {"text" : this.content[i].artists[0], "xLoc" : canvasH + 20, "yLoc" : canvasH / 1.1 , "zLoc" : 0};
+ else if (typeof this.content[i].artists[0] !== "string")
+ this.content[i].artists[0] = "Unknown";
+
+ var trackText = {"text" : this.content[i].title, "xLoc" : canvasH + 20, "yLoc" : canvasH / 2.5 , "zLoc" : 0};
+ var artistText = {"text" : this.content[i].artists[0], "xLoc" : canvasH + 20, "yLoc" : canvasH / 1.1 , "zLoc" : 0};
- if (this.content[i].coverArt && this.content[i].coverArt.complete)
+ if (this.content[i].coverArt && this.content[i].coverArt.complete && (this.content[i].coverArt.naturalWidth !== 0 || this.content[i].coverArt.naturalHeight !== 0) )
this.makeListBar(this.content[i].coverArt, i, artistText, trackText);
else
this.makeListBar(musicIcon, i, artistText, trackText);