home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2004 June
/
Chip_2004-06_cd1.bin
/
opsys
/
wmakeup
/
downloads
/
DTPM.wmz
/
text.js
< prev
next >
Wrap
Text File
|
2004-03-26
|
40KB
|
1,510 lines
//Called when the player view is first loaded
function On_Load()
{
SetViewState();
RefreshSources();
RefreshGenres();
RefreshArtists();
RefreshAlbums();
SetStartState();
UpdateMetadata();
allMusicInfo.value = GeneratePlaylistSummary();
}
function SetViewState()
{
viewMode = theme.loadPreference("viewMode");
if ((viewMode != "--") &&
(viewMode != "Main"))
{
theme.currentViewID = viewMode;
}
}
//Called when the player view is closed
function On_Close()
{
theme.savePreference("mainWidth", Main.width);
theme.savePreference("mainHeight", Main.height);
}
function SetStartState()
{
SetAlbumArtPanelState();
SetLeftPaneState();
SetBrowsePaneState();
//SetTimeState must occur before SetDisplayPanelState,
//so that Time displays are shown or hidden correctly in bar display
SetTimeState();
SetDisplayPanelState();
SetVisualStartState();
SetMainState();
}
function SetMainState()
{
mainWidth = theme.loadPreference("mainWidth");
mainHeight = theme.loadPreference("mainHeight");
if (mainWidth.toUpperCase() != "--")
{
Main.width = mainWidth;
}
if (mainHeight.toUpperCase() != "--")
{
Main.height = mainHeight;
}
}
//Called if the state of the current media source changes
//Typically called when opening new media
function OnOpenStateChange(NewState)
{
if (NewState == 'MediaOpen')
{
UpdateMetadata();
}
}
function OnPlayStateChange(NewState)
{
if ((NewState == 1)||(NewState == 2)||(NewState == 3))
{
if (player.currentMedia.ImageSourceWidth > 0)
{
ShowVisuals ();
}
else
{
if (!effectsView.visible)
{
HideVisuals();
}
else
{
ShowVisuals();
}
}
}
}
function SetVisualStartState()
{
visualisationVisible = theme.loadPreference("visualisationVisible");
if ((visualisationVisible.toUpperCase() == "FALSE") ||
(visualisationVisible.toUpperCase() == "--"))
{
HideVisuals();
}
else
{
ShowVisuals();
}
}
function ShowVisuals ()
{
playlistView.visible = false;
HideVisualizations.Visible = true;
ShowVisualizations.Visible = false;
if ((player.playState != 0) &&
(player.playState != 10) &&
(player.currentMedia.ImageSourceWidth > 0))
{
videoView.visible = true;
effectsView.visible = false;
}
else
{
videoView.visible = false;
effectsView.visible = true;
theme.savePreference("visualisationVisible", true);
}
}
function HideVisuals ()
{
playlistView.visible = true;
HideVisualizations.Visible = false;
ShowVisualizations.Visible = true;
if ((player.playState != 0) &&
(player.playState != 10) &&
(player.currentMedia.ImageSourceWidth > 0))
{
videoView.visible = false;
effectsView.visible = false;
}
else
{
videoView.visible = false;
effectsView.visible = false;
theme.savePreference("visualisationVisible", false);
}
}
//Called if the player mode (shuffle, loop, etc.) changes
function OnModeChange(NewMode, NewValue)
{
if (NewMode == "shuffle")
{
shuffleOn.visible = NewValue;
shuffleOff.visible = !NewValue;
}
else if (NewMode == "loop")
{
repeatOn.visible = NewValue;
repeatOff.visible = !NewValue;
}
}
//Update the sources when CD Media changes
function CdromMediaChange(CdromNum)
{
RefreshSources();
}
//Update the sources when the playlist collection changes
function PlaylistCollectionChange()
{
RefreshSources();
}
function MediaChange(Item)
{
RefreshGenres();
RefreshArtists();
RefreshAlbums();
}
function PlaylistUpdated()
{
allMusicInfo.value = GeneratePlaylistSummary();
}
function GeneratePlaylistSummary()
{
var summary = "";
var allMedia = player.newPlaylist("", "");
allMedia = playlistView.playlist;
var fileSize = new Number();
var fileTime = new Number();
//Iterate through all media in the current playlist view
for (var i =0; i < allMedia.count; i++)
{
//Retrieve the current item's size in bytes and time in seconds
thisSize = new Number (allMedia.item(i).getItemInfo("FileSize"));
thisTime = new Number(allMedia.item(i).getItemInfo("Duration"));
//Add these to the total size and total time
fileSize += thisSize;
fileTime += thisTime;
}
//Add the song count to the summary
summary = allMedia.count + " songs, ";
//Calculate the number of days, hours, minutes and seconds in the playlist
days = Math.floor (fileTime/86400);
daysRemainder = fileTime%86400;
hours = Math.floor (daysRemainder/3600);
hoursRemainder = daysRemainder%3600;
minutes = Math.floor (hoursRemainder/60);
seconds = Math.floor(hoursRemainder%60);
/*The following code produces the "real" iTunes datetime format of
4.9 (time period)*/
//If the number of days is a positive integer, calculate the remaining fraction of days and add this to the summary
if (days > 0)
{
dayFraction = Math.round((hours*10)/24);
if (dayFraction < 10)
{
summary += days + "." + dayFraction + " days, ";
}
else
{
summary += (days + 1) + " days, ";
}
}
//Otherwise, if the number of hours is a positive integer, calculate the remaining fraction of hours and add this to the summary
else if (hours > 0)
{
hourFraction = Math.round((minutes*10)/60);
if (hourFraction < 10)
{
summary += hours + "." + hourFraction + " hours, ";
}
else
{
summary += (hours + 1) + " hours, ";
}
}
//Otherwise, if the number of minutes is a positive integer, calculate the remaining fraction of minutes and add this to the summary
else if (minutes > 0)
{
minuteFraction = Math.round((seconds*10)/60);
if (minuteFraction < 10)
{
summary += minutes + "." + minuteFraction + " minutes, ";
}
else
{
summary += (minutes + 1) + " minutes, ";
}
}
//Otherwise, add the seconds to the summary
else if (seconds > 0)
{
summary += seconds + "seconds, ";
}
/*
The following commented section of code produces alternate datetime format of
(dd:hh:)mm:ss
if (days > 0)
{
summary += days + ":";
}
if ((days > 0) &&
(hours < 10))
{
summary += "0" + hours + ":";
}
else if (((days > 0) &&
(hours >=10)) ||
((days == 0) &&
(hours > 0)))
{
summary += hours + ":";
}
if ((hours > 0) &&
(minutes < 10))
{
summary += "0" + minutes + ":";
}
else
{
summary += minutes + ":";
}
if (seconds < 10)
{
summary += "0" + seconds;
}
else
{
summary += seconds;
}
summary += " total time, ";*/
//Calculate the GigaBytes, MegaBytes, and KiloBytes used by the current playlist
var gigabytes = Math.floor(fileSize/1073741824);
var gigabytesRemainder = fileSize%1073741824;
var megabytes = Math.floor(gigabytesRemainder/1048576);
var megabytesRemainder = gigabytesRemainder%1048576;
var kilobytes = Math.floor(megabytesRemainder/1024);
//If the number of Gb is a positive integer, add it and it's fraction to the summary
if (gigabytes > 0)
{
summary += gigabytes + "." + megabytes.toString().substr(0,2) + "GB";
}
//Otherwise, if the number of Mb is a positive integer, add it and it's fraction to the summary
else if (megabytes > 0)
{
summary += megabytes + "." + kilobytes.toString().substr(0,2) + "MB";
}
//Otherwise, if the number of Kb is a positive integer, add it and it's fraction to the summary
else
{
summary += kilobytes + "KB";
}
return summary;
}
function ResizeBars()
{
if ((bars.width-4)/2 <= 300)
{
leftBars.width = (bars.width-4)/2;
rightBars.width = (bars.width-4)/2;
}
else
{
leftBars.width = 300;
rightBars.width = 300;
}
leftBars.left = ((bars.width-4)/2) - leftBars.width;
rightBars.left = bars.width - ((bars.width-4)/2);
}
//Search the entire media collection and show the results in the playlist pane.
function SearchBoxChanged()
{
//If the user pressed return, do the search
if (event.keycode==13)
{
playlistView.playlist = DoSearch (searchText.value);
}
}
function ShowSearchHistory()
{
if (searchHistory.itemCount > 0)
{
searchHistory.show();
}
}
function HistorySearchMedia()
{
playlistView.playlist = DoSearch (searchHistory.getItem(searchHistory.selectedItem));
}
//Search the entire media collection for the input search string, and return a playlist of results
function DoSearch(searchstring)
{
//Retrieve all tracks
var alltracks = player.mediaCollection.getAll();
//Retrieve the atom indexes of the "Title", "WM/AlbumTitle", "Author" and "WM/AlbumArtist" atoms
//to speed up the search
var trackTitleAtom = player.mediaCollection.getMediaAtom("Title");
var albumTitleAtom = player.mediaCollection.getMediaAtom("WM/AlbumTitle");
var authorAtom = player.mediaCollection.getMediaAtom("Author");
var albumArtistAtom = player.mediaCollection.getMediaAtom("WM/AlbumArtist");
var plylst;
//Create the playlist to return
plylst = player.newPlaylist("","");
//Iterate through all the media
for (var i = 0; i < alltracks.count; i++)
{
//Retrieve the media info for the current item
trackName = alltracks.item(i).getItemInfoByAtom(trackTitleAtom).toUpperCase();
trackAlbum = alltracks.item(i).getItemInfoByAtom(albumTitleAtom).toUpperCase();
trackAuthor = alltracks.item(i).getItemInfoByAtom(authorAtom).toUpperCase();
trackArtist = alltracks.item(i).getItemInfoByAtom(albumArtistAtom).toUpperCase();
//If the current item's info contains the search string, add it to the playlist to return
if ((trackName.indexOf(searchstring.toUpperCase()) != -1) ||
(trackAlbum.indexOf(searchstring.toUpperCase()) != -1) ||
(trackAuthor.indexOf(searchstring.toUpperCase()) != -1) ||
(trackArtist.indexOf(searchstring.toUpperCase()) != -1))
{
plylst.appendItem( alltracks.item(i) );
}
}
if ((searchHistory.findItem (0, searchstring) == -1) &&
(searchHistory.itemCount > 0))
{
searchHistory.appendItem(searchstring);
}
else if (searchHistory.itemCount == 0)
{
searchHistory.appendItem(searchstring);
}
searchText.value = "";
return plylst;
}
//Refreshes the sources list in the left pane
function RefreshSources()
{
//Initially, clear all entries to ensure no duplication
sources.deleteAll();
//Append the 3 default entries
sources.appendItem("Now Playing");
sources.appendItem("All Music");
sources.appendItem("All Video");
//Iterate through CD/DVD drives and append their drive letter (to allow identification of drives) and media name
var cdromCollection = player.cdromCollection;
for (var i = 0; i < cdromCollection.Count; i++)
{
var cdPlaylists = new Array();
sources.appendItem (cdromCollection.item(i).driveSpecifier + " " + cdromCollection.item(i).Playlist.Name);
}
//Iterate through the playlist collection and append all items here
var playlistCollection = player.playlistCollection;
var playlistArray = playlistCollection.getAll();
var playlistCount = playlistArray.count;
for (var i = 0; i < playlistCount; i++)
{
sources.appendItem(playlistArray.item(i).getItemInfo("Title"));
}
}
function ShowGenrePlaylist()
{
var newPlaylist = FilterByGenre(genres.getItem(genres.selectedItem));
playlistView.playlist = newPlaylist;
}
function PlayGenrePlaylist()
{
//If the playlist isn't the currently playing playlist or the "Now Playing" item, play it
if (player.currentPlaylist.Name != genres.getItem(genres.selectedItem))
{
player.currentPlaylist = playlistView.playlist;
player.currentPlaylist.Name = genres.getItem(genres.selectedItem);
player.controls.play();
}
}
//Update the genre list in the browse pane
function RefreshGenres()
{
//Retrieve all genre titles
var mediaCollection = player.mediaCollection;
var allGenres = mediaCollection.getAttributeStringCollection("WM/Genre", "audio");
//Clear the list of genres and add the "All" item
genres.deleteAll();
genres.appendItem("All (" + allGenres.count + " Genres)");
//Iterate through the array of genres, adding them as appropriate
for (var i = 0; i < allGenres.count; i++)
{
if (allGenres.item(i) != "")
{
genres.appendItem(allGenres.item(i));
}
else
{
genres.appendItem("Unknown Genre");
}
}
}
//Filter the artist and album lists by the specified genre
function FilterByGenre(genreName)
{
var newPlaylist;
//If the genre is not "All"
if (genreName.indexOf("All (") == -1)
{
var thisGenre;
//If the user has selected an "Unknown Genre", change the genre name accordingly
if (genreName != "Unknown Genre")
{
thisGenre = genreName;
}
else
{
thisGenre = "";
}
//Retrieve the playlist for the selected genre
newPlaylist = player.mediaCollection.getByGenre(thisGenre);
//Clear the artist and album lists
artists.deleteAll();
albums.deleteAll();
//Set the variables to speed up the search
var albumTitleAtom = player.mediaCollection.getMediaAtom("Album");
var authorAtom = player.mediaCollection.getMediaAtom("Author");
var artistCount = 0;
var albumCount = 0;
//Iterate through the playlist to set the artists and albums
for (var i = 0; i < newPlaylist.count; i++)
{
//Retrieve the metadata for the item
var thisItem = newPlaylist.item(i);
var thisArtist = thisItem.getItemInfoByAtom(authorAtom);
var thisAlbum = thisItem.getItemInfoByAtom(albumTitleAtom);
//Attempt to find the current artist in the artists list
var matched = false;
for (var j = 0; j < artists.itemCount; j++)
{
var artistToMatch = artists.getItem(j);
if ((thisArtist.toUpperCase() == artistToMatch.toUpperCase())||
((thisArtist == "") && (artistToMatch == "Unknown Artist")))
{
matched = true;
}
}
//If the artist was not found in the list, find the point at which they should be inserted and add them
if (!matched)
{
var artistInstertPoint = FindArtistInsertPoint(thisArtist, -1, artists.itemCount);
if (thisArtist == "")
{
thisArtist = "Unknown Artist";
}
artists.insertItem (artistInstertPoint, thisArtist);
artistCount = artistCount + 1;
}
//Attempt to find the current album in the albums list
matched = false;
for (var j = 0; j < albums.itemCount; j++)
{
var albumToMatch = albums.getItem(j);
if ((thisAlbum.toUpperCase() == albumToMatch.toUpperCase()) ||
((thisAlbum == "") && (albumToMatch == "Unknown Album")))
{
matched = true;
}
}
//If the album was not found in the list, find the point at which they should be inserted and add them
if (!matched)
{
var albumInsertPoint = FindAlbumInsertPoint(thisAlbum, -1, albums.itemCount);
if (thisAlbum == "")
{
thisAlbum = "Unknown Album";
}
albums.insertItem (albumInsertPoint, thisAlbum);
albumCount = albumCount + 1;
}
}
//Add the "All" entries at the beginning of the list
artists.insertItem(0, "All (" + artistCount + " Artists)");
albums.insertItem(0, "All (" + albumCount + " Albums)");
}
//If the user has selected "All" genres
else
{
//Refresh the artist list
RefreshArtists();
//Refresh the album list
RefreshAlbums();
//Set the playlist to all media in the media collection
newPlaylist = player.mediaCollection.getAll();
}
return newPlaylist;
}
//Finds the point in the artist list at which the current item should be added
function FindArtistInsertPoint (artistName, lo, hi)
{
var position;
//If the artistName begins with "The", it should be positioned based on the rest of the name.
//E.g. "The Verve" should be under "V" for "Verve"
var testName = artistName;
if (testName.indexOf ("The ") == 0)
{
testName = artistName.substring(4,artistName.length);
}
//If there is less than 1 item between the top and bottom, insertion point should be 1 above the bottom
if ((hi - lo) <= 1)
{
position = lo + 1;
}
//Otherwise, divide the list by two
else
{
var mid = (lo + hi) / 2;
artistToMatch = artists.getItem(mid);
if (artistToMatch == "Unknown Artist")
{
artistToMatch = "";
}
//If the artist to find is below the half-mark in the list, find the position between the bottom and half
if (artistToMatch > artistName)
{
position = FindArtistInsertPoint (artistName, lo, mid);
}
//If the artist is above the half mark, find the position between half and the top
else if (artistToMatch < artistName)
{
position = FindArtistInsertPoint (artistName, mid, hi);
}
//Otherwise, if the middle item matches the item to find, return -1
else if (artistToMatch == testName)
{
position = -1;
}
}
return position;
}
//Finds the point in the album list at which the current item should be added
function FindAlbumInsertPoint (albumName, lo, hi)
{
var position;
//If the album name begins with "The", it should be positioned based on the rest of the name.
//E.g. "The Best Of..." should be under "B" for "Best Of..."
var testName = albumName;
if (testName.indexOf ("The ") == 0)
{
testName = albumName.substring(4,albumName.length);
}
//If there is less than 1 item between the top and bottom, insertion point should be 1 above the bottom
if ((hi - lo) <= 1)
{
position = lo + 1;
}
//Otherwise, divide the list by zero
else
{
var mid = (lo + hi) / 2;
albumToMatch = albums.getItem(mid);
if (albumToMatch == "Unknown Album")
{
albumToMatch = "";
}
//If the album to find is below the half-mark, find the position between the bottom and half
if (albumToMatch > albumName)
{
position = FindAlbumInsertPoint (albumName, lo, mid);
}
//If the album is above the half mark, find the position between half and the top
else if (albumToMatch < albumName)
{
position = FindAlbumInsertPoint (albumName, mid, hi);
}
//Otherwise, if the middle item matches the item to find, return -1
else if (albumToMatch == testName)
{
position = -1;
}
}
return position;
}
function ShowArtistPlaylist()
{
var newPlaylist = FilterByArtist(artists.getItem(artists.selectedItem));
playlistView.playlist = newPlaylist;
}
function PlayArtistPlaylist()
{
//If the playlist isn't the currently playing playlist or the "Now Playing" item, play it
if (player.currentPlaylist.Name != artists.getItem(artists.selectedItem))
{
player.currentPlaylist = playlistView.playlist;
player.currentPlaylist.Name = artists.getItem(artists.selectedItem);
player.controls.play();
}
}
//Update the artist list in the browse pane
function RefreshArtists()
{
//Retrieve all artist names from the media collection
var mediaCollection = player.mediaCollection;
var allArtists = mediaCollection.getAttributeStringCollection("Author","audio");
//Clear the artist list and add the all artists item
artists.deleteAll();
artists.appendItem("All (" + allArtists.count + " Artists)");
//Iterate through the artists, adding as appropriate
for (var i = 0; i< allArtists.count; i++)
{
if (allArtists.item(i) != "")
{
artists.appendItem(allArtists.item(i));
}
else
{
if ((artists.itemCount > 1) &&
(artists.getItem(1) != "Unknown Artist"))
{
artists.insertItem(1, "Unknown Artist");
}
else
{
artists.appendItem("Unknown Artist");
}
}
}
}
//Filters the album list based on the input artist and returns the playlist for that artist
function FilterByArtist(artistName)
{
var newPlaylist
//If the artist selected is not "All"
if (artistName.indexOf("All (") == -1)
{
var thisArtist;
//Set the artist name to "" for unknown artists
if (artistName != "Unknown Artist")
{
thisArtist = artistName;
}
else
{
thisArtist = "";
}
//Retrieve the playlist for the artist
newPlaylist = player.mediaCollection.getByAuthor(thisArtist);
//Clear the album list and set the initial variables
albums.deleteAll();
var albumTitleAtom = player.mediaCollection.getMediaAtom("Album");
var genreAtom = player.mediaCollection.getMediaAtom("WM/Genre");
//Retrieve the selected genre, or if no genre or all genres are selected, set the genre to an empty string
var currentGenre = "";
if (genres.selectedItem != -1)
{
currentGenre = genres.getItem(genres.selectedItem);
}
if (currentGenre.substring(0, 5) == "All (")
{
currentGenre = "";
}
var albumCount = 0;
//Iterate through the items in the artist's playlist
for (var i = 0; i < newPlaylist.count; i++)
{
//Retrieve the current item's genre and album title
var thisItem = newPlaylist.item(i);
var thisGenre = thisItem.getItemInfoByAtom(genreAtom);
var thisAlbum = thisItem.getItemInfoByAtom(albumTitleAtom);
//Attempt to find the current album in the albums list
var matched = false;
for (var j = 0; j < albums.itemCount; j++)
{
var albumToMatch = albums.getItem(j);
if ((thisAlbum.toUpperCase() == albumToMatch.toUpperCase()) ||
((thisAlbum == "") && (albumToMatch == "Unknown Album")))
{
matched = true;
}
}
//If the album is not in the current list and either the selected genre is "all" or the current genre matches
//that of the current item, add the album at the appropriate position in the list
if ((!matched) &&
((currentGenre == "") ||
(currentGenre.toUpperCase() == thisGenre.toUpperCase())))
{
var albumInsertPoint = FindAlbumInsertPoint(thisAlbum, -1, albums.itemCount);
if (thisAlbum == "")
{
thisAlbum = "Unknown Album";
}
albums.insertItem (albumInsertPoint, thisAlbum);
albumCount = albumCount + 1;
}
}
//Add the all albums item
albums.insertItem(0, "All (" + albumCount + " Albums)");
}
//Otherwise, refresh the artist and album panes by filtering on the selected genre
else
{
var selected = genres.selectedItem;
if (selected == -1)
{
selected = 0;
}
//Set the playlist to all media in the media collection
newPlaylist = FilterByGenre(genres.getItem(selected));
}
return newPlaylist;
}
//Update the album list in the browse pane
function RefreshAlbums()
{
//Retrieve all albums titles in the media collection
var mediaCollection = player.mediaCollection;
var allAlbums = mediaCollection.getAttributeStringCollection("Album","audio");
//Clear the album list and add the "all" item
albums.deleteAll();
albums.appendItem("All (" + allAlbums.count + " Albums)");
//Iterate through the album titles, adding to the list as appropriate
for (var i=0; i<allAlbums.count; i++)
{
if (allAlbums.item(i) != "")
{
albums.appendItem(allAlbums.item(i));
}
else
{
if ((albums.itemCount > 1) &&
(albums.getItem(1) != "Unknown Album"))
{
albums.insertItem(1, "Unknown Album");
}
else
{
albums.appendItem("Unknown Album");
}
}
}
}
function ShowAlbumPlaylist()
{
var newPlaylist = FilterByAlbum(albums.getItem(albums.selectedItem));
playlistView.playlist = newPlaylist;
}
function PlayAlbumPlaylist()
{
//If the playlist isn't the currently playing playlist or the "Now Playing" item, play it
if (player.currentPlaylist.Name != artists.getItem(albums.selectedItem))
{
player.currentPlaylist = playlistView.playlist;
player.currentPlaylist.Name = albums.getItem(albums.selectedItem);
player.controls.play();
}
}
function FilterByAlbum(albumName)
{
if (albumName.indexOf("All (") == -1)
{
if (albumName == "Unknown Album")
{
albumName = "";
}
//Retrieve the selected artist, or if no artist or all artists are selected, set the artist to an empty string
var artistName = "";
if (artists.selectedItem != -1)
{
artistName = artists.getItem(artists.selectedItem);
}
if (artistName.substring(0, 5) == "All (")
{
artistName = "";
}
//Retrieve the selected genre, or if no genre or all genres are selected, set the genre to an empty string
var currentGenre = "";
if (genres.selectedItem != -1)
{
currentGenre = genres.getItem(genres.selectedItem);
}
if (currentGenre.substring(0, 5) == "All (")
{
currentGenre = "";
}
var artistAtom = player.mediaCollection.getMediaAtom("Author");
var genreAtom = player.mediaCollection.getMediaAtom("WM/Genre");
var newPlaylist = player.mediaCollection.getByAlbum(albumName);
var tempPlaylist = player.newPlaylist("", "");
for (var i = 0; i < newPlaylist.count; i++)
{
if (((newPlaylist.item(i).getItemInfoByAtom(artistAtom).toUpperCase() == artistName.toUpperCase()) ||
(artistName == "")) &&
((newPlaylist.item(i).getItemInfoByAtom(genreAtom).toUpperCase() == currentGenre.toUpperCase()) ||
(currentGenre == "")))
{
tempPlaylist.appendItem (newPlaylist.item(i));
}
}
}
else
{
var selected = artists.selectedItem;
if (selected == -1)
{
selected = 0;
}
//Set the playlist to all media for the artist
tempPlaylist = FilterByArtist(artists.getItem(selected));
}
return tempPlaylist;
}
//Shows the currently selected item in the sources listbox in the playlist
function ShowSourcePlaylist()
{
playlistView.playlist = GetSourcePlaylist();
}
//Plays the currently selected item in the sources listbox
function PlaySourcePlaylist()
{
//If the playlist isn't the currently playing playlist or the "Now Playing" item, play it
if ((player.currentPlaylist.Name != sources.getItem(sources.selectedItem)) &&
(sources.getItem(sources.selectedItem) != "Now Playing"))
{
playlistView.playlist = GetSourcePlaylist();
player.currentPlaylist = playlistView.playlist;
player.currentPlaylist.Name = sources.getItem(sources.selectedItem);
player.controls.play();
}
}
//Retrieves the playlist for the item selected in the source pane
function GetSourcePlaylist()
{
var newPlaylistName = sources.getItem(sources.selectedItem);
var sourcePlaylist;
//If the selected item is "Now Playing", retrieve the current playlist from the player
if (newPlaylistName == "Now Playing")
{
sourcePlaylist = player.currentPlaylist;
}
//If the selected item is "All Music", retrieve a playlist of all audio in the media collection
else if (newPlaylistName == "All Music")
{
sourcePlaylist = player.mediaCollection.getByAttribute("MediaType", "audio");
}
//If the selected item is "All Video", retrieve a playlist of all video in the media collection
else if (newPlaylistName == "All Video")
{
sourcePlaylist = player.mediaCollection.getByAttribute("MediaType", "video");
}
//If the selected item is a CD/DVD drive, retrieve that drive's playlist
else if (newPlaylistName.indexOf (": ") != -1)
{
var driveSpecifier = newPlaylistName.substr(0, 2);
var cdromCollection = player.cdromCollection;
for (var i = 0; i < cdromCollection.Count; i++)
{
if (driveSpecifier == cdromCollection.item(i).driveSpecifier)
{
sourcePlaylist = cdromCollection.item(i).playlist;
}
}
}
//Otherwise, the item is assumed to be a standard playlist in the playlist collection
else
{
var newPlaylist = player.playlistCollection.getByName(newPlaylistName);
if (newPlaylist.count > 0)
{
sourcePlaylist = newPlaylist.item(0);
}
}
return sourcePlaylist;
}
//Update metadata view of the player
function UpdateMetadata()
{
//Ensure that the metadata text only scrolls when needed
if (metadata.textWidth <= metadata.width)
{
metadata.scrolling = false;
}
else
{
metadata.scrolling = true;
}
//Ensure that the time views are centered
current.width = currentTimeLabel.textWidth + duration.textWidth;
remaining.width = remainingTimeLabel.textWidth + duration.textWidth;
//Update the album art image.
//Because of a bug in WMP, we must first change the backgroundImage to "" before setting the new image
albumArt.backgroundImage = "";
albumArt.backgroundImage = "WMPImage_AlbumArtLarge";
}
function SetBrowsePaneState()
{
browsePaneVisible = theme.loadPreference("browsePaneVisible");
if ((browsePaneVisible.toUpperCase() == "TRUE") ||
(browsePaneVisible.toUpperCase() == "--"))
{
browsePaneHeight = theme.loadPreference("browsePaneHeight");
if (browsePaneHeight.toUpperCase() != "--")
{
browsePaneSlider.value = 200 - browsePaneHeight;
}
}
else
{
browsePaneSlider.value = 200;
}
ResizeBrowsePane();
}
//By setting the value of the left pane slider to 0 or 150 alternately, we can toggle visibility
//of the left pane, using the native value_onchange of the slider
function ToggleBrowsePane()
{
if (browsePaneSlider.value >= 196)
{
browsePaneHeight = theme.loadPreference("browsePaneHeight");
if (browsePaneHeight.toUpperCase() != "--")
{
browsePaneSlider.value = 200 - browsePaneHeight;
}
else
{
browsePaneSlider.value = 100;
}
}
else
{
browsePaneSlider.value = 200;
}
ResizeBrowsePane();
}
//Resize the browse pane's height to match the slider's value
function ResizeBrowsePane()
{
browsePane.height = 200- browsePaneSlider.value;
genrePane.height = browsePane.height - 4;
artistPane.height = browsePane.height - 4;
albumPane.height = browsePane.height - 4;
genres.height = genrePane.height - 16;
artists.height = artistPane.height - 16;
albums.height = albumPane.height - 16;
//If the browse pane is closed sufficiently, hide it's contents
if (browsePane.height <= 4)
{
playlistPane.top = 0;
playlistPane.height = contentPane.height;
browsePaneSlider.top = 49;
leftBrowsePane.visible = false;
rightBrowsePane.visible = false;
topBrowsePane.visible = false;
bottomBrowsePane.visible = false;
genreArtistSeperator.visible = false;
artistAlbumSeperator.visible = false;
genres.visible = false;
artists.visible = false;
albums.visible = false;
browse.down = false;
theme.savePreference("browsePaneVisible", false);
}
//Otherwise, ensure it's contents are visible
else
{
playlistPane.top = browsePane.height + 10;
playlistPane.height = contentPane.height - browsePane.height - 10;
browsePaneSlider.top = 60;
leftBrowsePane.visible = true;
rightBrowsePane.visible = true;
topBrowsePane.visible = true;
bottomBrowsePane.visible = true;
//The left and right browse pane heights must be corrected since the pane is closed initially
leftBrowsePane.Height = browsePane.Height - 4;
rightBrowsePane.Height = browsePane.Height - 4;
genreArtistSeperator.Height = browsePane.Height - 4;
genreArtistSeperator.visible = true;
artistAlbumSeperator.Height = browsePane.Height - 4;
artistAlbumSeperator.visible = true;
genres.visible = true;
artists.visible = true;
albums.visible = true;
browse.down = true;
theme.savePreference("browsePaneHeight", browsePane.height);
theme.savePreference("browsePaneVisible", true);
}
}
function UpdateBrowseWidths()
{
genrePane.width = (browsePane.width - 6)/3;
artistPane.width = (browsePane.width - 6)/3;
albumPane.width = (browsePane.width - 6)/3;
artistPane.left = genrePane.width + 3;
albumPane.left = artistPane.left + artistPane.width + 1;
genreArtistSeperator.left = genrePane.width + 2;
artistAlbumSeperator.left = artistPane.left + artistPane.width;
}
function SetLeftPaneState()
{
leftPaneVisible = theme.loadPreference("leftPaneVisible");
if ((leftPaneVisible.toUpperCase() == "TRUE") ||
(leftPaneVisible.toUpperCase() == "--"))
{
leftPaneWidth = theme.loadPreference("leftPaneWidth");
if (leftPaneWidth.toUpperCase() != "--")
{
leftPaneSlider.value = leftPaneWidth;
}
else
{
leftPaneSlider.value = 150;
}
}
else
{
leftPaneSlider.value = 0;
}
ResizeLeftPane();
}
//By setting the value of the left pane slider to 0 or 150 alternately, we can toggle visibility
//of the left pane, using the native value_onchange of the slider
function ToggleLeftPane()
{
if (leftPaneSlider.value <= 4)
{
leftPaneWidth = theme.loadPreference("leftPaneWidth");
if (leftPaneWidth.toUpperCase() != "--")
{
leftPaneSlider.value = leftPaneWidth;
}
else
{
leftPaneSlider.value = 150;
}
}
else
{
leftPaneSlider.value = 0;
}
ResizeLeftPane();
}
//Resize the left pane's width to match the slider's value, and compensate for the height change on
//the album art
function ResizeLeftPane()
{
leftPane.width = leftPaneSlider.value;
albumArtPane.top = centerPane.height - albumArtPane.height;
albumArtPane.height = albumArtPane.width + 18;
if (albumArtPane.zindex != -1)
{
sourcePane.height = albumArtPane.top;
}
//If the left pane is closed sufficiently, hide it's contents
if (leftPane.width <= 4)
{
contentPane.left = 0;
contentPane.width = centerPane.width;
leftPaneSlider.left = 1;
leftSourcePane.visible = false;
rightSourcePane.visible = false;
topSourcePane.visible = false;
bottomSourcePane.visible = false;
leftAlbumArtPane.visible = false;
rightAlbumArtPane.visible = false;
topAlbumArtPane.visible = false;
bottomAlbumArtPane.visible = false;
AlbumArtPanelOff.enabled = false;
AlbumArtPanelOn.enabled = false;
theme.savePreference("leftPaneVisible", false);
}
//Otherwise, ensure it's contents are visible
else
{
contentPane.left = leftPane.width + 8;
contentPane.width = centerPane.width - leftPane.width - 8;
leftPaneSlider.left = 9;
leftSourcePane.visible = true;
rightSourcePane.visible = true;
topSourcePane.visible = true;
bottomSourcePane.visible = true;
leftAlbumArtPane.visible = true;
rightAlbumArtPane.visible = true;
topAlbumArtPane.visible = true;
bottomAlbumArtPane.visible = true;
AlbumArtPanelOff.enabled = true;
AlbumArtPanelOn.enabled = true;
theme.savePreference("leftPaneWidth", leftPane.width);
theme.savePreference("leftPaneVisible", true);
}
}
function SetAlbumArtPanelState()
{
albumArtPanelVisible = theme.loadPreference("albumArtVisible");
if ((albumArtPanelVisible.toUpperCase() == "-1") ||
(albumArtPanelVisible.toUpperCase() == "--"))
{
HideAlbumArtPanel();
}
else
{
ShowAlbumArtPanel();
}
}
//To show the album art, set its z-index to 1 (above the skin), and the source
//pane's height to the top of the album art, updating the buttons accordingly
function ShowAlbumArtPanel()
{
sourcePane.height = albumArtPane.top;
albumArtPane.zindex = 1;
AlbumArtPanelOff.visible = false;
AlbumArtPanelOn.visible = true;
theme.savePreference("albumArtVisible", albumArtPane.zindex);
}
//To hide the album art, we set it's z-index to -1 (below the skin itself), and set the
//source pane to the same height as the center pane, updating the buttons accordingly
function HideAlbumArtPanel()
{
sourcePane.Height = centerPane.Height;
albumArtPane.zindex = -1;
AlbumArtPanelOff.visible = true;
AlbumArtPanelOn.visible = false;
theme.savePreference("albumArtVisible", albumArtPane.zindex);
}
//Toggle the two display panels
function ToggleDisplayPanels()
{
if (barDisplayPanel.visible)
{
ShowSongDisplayPanel();
}
else
{
ShowBarDisplayPanel();
}
}
function SetDisplayPanelState()
{
songDisplayVisible = theme.loadPreference("songDisplayVisible");
if ((songDisplayVisible.toUpperCase() == "TRUE") ||
(songDisplayVisible.toUpperCase() == "--"))
{
ShowSongDisplayPanel();
}
else
{
ShowBarDisplayPanel();
}
}
//Show the song display panel, hide the bar display, set the time display accordingly, and save the state
function ShowSongDisplayPanel()
{
songDisplayPanel.visible = true;
barDisplayPanel.visible = false;
bars.visible = false;
leftBarGrid.visible = false;
rightBarGrid.visible = false;
theme.savePreference("songDisplayVisible", songDisplayPanel.visible);
SetTimeState();
}
//Show the bar display panel, hide the song display and the time displays, and save the state
function ShowBarDisplayPanel()
{
songDisplayPanel.visible = false;
barDisplayPanel.visible = true;
remaining.visible = false;
current.visible = false;
bars.visible = true;
leftBarGrid.visible = true;
rightBarGrid.visible = true;
theme.savePreference("songDisplayVisible", songDisplayPanel.visible);
}
//******** Time display managment ********//
///Retrieve the time remaining on the current media
function GetRemainingTime()
{
//Retrieve the number of whole seconds playback remaining on the current media
remainingSeconds = Math.round(player.currentMedia.duration - player.controls.currentPosition);
//Calculate hours, minutes and seconds remaining
remainingHours = Math.round(remainingSeconds/3600);
remainderMinutes = Math.round(remainingSeconds%3600);
remainingMinutes = Math.round(remainderMinutes/60);
remainderSeconds = Math.round(remainderMinutes%60);
var remain = "";
//If the number of hours remaining is not zero, and greather than 10, just display it
if ((remainingHours != 0) &&
(remainingHours >= 10))
{
remain += remainingHours + ":";
}
//If the number of hours remaining is not zero and less than 10, we must append a leading 0
else if ((remainingHours != 0) &&
(remainingHours < 10))
{
remain += "0" + remainingHours + ":";
}
//If there are zero hours remaining, we do not display hours
//If the number of minutes is less than 10, we must append a leading 0
if (remainingMinutes < 10)
{
remain += "0" + remainingMinutes;
}
//Otherwise just display the minutes
else
{
remain += remainingMinutes;
}
remain += ":";
//If the number of seconds is less than 10, append a leading 0
if (remainderSeconds < 10)
{
remain += "0" + remainderSeconds;
}
//Otherwise just display the seconds
else
{
remain += remainderSeconds;
}
return remain;
}
//Set the current state of the time display
function SetTimeState()
{
//Retrieve the saved state of the time display
elapsedTimeVisible = theme.loadPreference("elapsedTimeVisible");
//If the elapsed time was previously visible, show it
if ((elapsedTimeVisible.toUpperCase() == "TRUE") ||
(elapsedTimeVisible.toUpperCase() == "--"))
{
ShowElapsedTime();
}
//Otherwise show the remaining time
else
{
ShowRemainingTime();
}
}
//Toggle the time display
function ToggleTimeDisplay()
{
if (current.visible)
{
ShowRemainingTime();
}
else
{
ShowElapsedTime();
}
}
//Show the elapsed time and store the state
function ShowElapsedTime()
{
remaining.visible = false;
current.visible = true;
theme.savePreference("elapsedTimeVisible", current.visible);
}
//Show the remaining time and store the state
function ShowRemainingTime()
{
remaining.visible = true;
current.visible = false;
theme.savePreference("elapsedTimeVisible", current.visible);
}
function OnOpenStateChange()
{
if(player.OpenState == osMediaOpen)
{
UpdateMetadata();
}
}
function UpdateMetadata()
{
metadata.value =
player.currentmedia.getiteminfo("author");
var temp = player.currentmedia.name;
if(temp != "")
{
if(metadata.value != "")
{
metadata.value += " -- ";
}
metadata.value += temp;
}
metadata.scrolling = metadata.textWidth>metadata.width;
}
function openpl() {
if(player.currentMedia.ImageSourceWidth > 0 )
{
video.visible = false;
vis.visible = false;
screen.moveto(-300,19,1000);
pl.visible = true;
eqbase.visible = false;
trackinfo.visible = false;
} else { }
}