Skip to content

Commit

Permalink
Added a new "simulatePlatform" value which can be used to select whic…
Browse files Browse the repository at this point in the history
…h simulation mode the iTunes Emulator will run in. Setting it to "AppleTV" for example will expose the getSystemSounds object which can be used to generate navigation sounds.

Added support for "AppleTV" simulation. Some properties are NOT available on AppleTV and so are removed if this platform is selected; however there are also some features unique to the AppleTV. Mainly this is the SystemSounds object which allows you to generate navigation sounds.

Added navigations sounds for AppleTV simulation.
  • Loading branch information
Solitude committed Nov 9, 2009
1 parent aa271e0 commit 99f572f
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 6 deletions.
40 changes: 34 additions & 6 deletions emulator/lib/Emulator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include("emulator/lib/Library.js");
include("emulator/lib/SystemSounds.js");
include("emulator/lib/Playlist.js");

function iTunesEmulator(iTunesMusicLibraryURL)
Expand All @@ -14,15 +15,29 @@ function iTunesEmulator(iTunesMusicLibraryURL)
this._trackList = null;
this._trackNumber = 0;

var baseURLParts = location.href.split("\\").join("/").split("/");
baseURLParts.pop();
this._baseURL = baseURLParts.join("/") + "/";

/* System sounds for AppleTV */
this._systemSounds = new SystemSounds();

/* Global iTunes properties */
this.platform = "Mac";
if (navigator.appVersion.indexOf("Win")!=-1) this.platform="Win";
if (navigator.appVersion.indexOf("Mac")!=-1) this.platform="Mac";
this.version = "9.0.2";
this.quickTimeVersion = "7.6.3";
if (navigator.appVersion.indexOf("Win") != -1) this.platform = "Win";
if (navigator.appVersion.indexOf("Mac") != -1) this.platform = "Mac";

if (typeof simulatePlatform != "undefined") {
if (simulatePlatform.toLowerCase().substr(0,3) == "win") this.platform = "Win";
if (simulatePlatform.toLowerCase().substr(0,3) == "mac") this.platform = "Mac";
if (simulatePlatform.toLowerCase().substr(0,7) == "appletv") this.platform = "AppleTV";
}

this.version = (this.platform == "AppleTV") ? "3.0" : "9.0.2";
this.quickTimeVersion = (this.platform == "AppleTV") ? "7.1.8" : "7.6.3";
this.acceptedLanguages = "en-us, en;q=0.50";

this.volume = 1;
this.volume = 0.99;
this.isMuted = false;
this.currentPlayerState = this.StoppedState;
this.currentPlayingTrack = null;
Expand All @@ -34,7 +49,10 @@ function iTunesEmulator(iTunesMusicLibraryURL)
this.waveform = null;

this.isCoverFlowAvailable = false;
this.screenReaderRunning = false;

if (this.platform != "AppleTV") {
this.screenReaderRunning = false;
}

this._audioEngine = new Audio();
this._audioEngine.style.display = "none";
Expand Down Expand Up @@ -184,6 +202,16 @@ iTunesEmulator.prototype.createTempPlaylist = function()
return thePlaylist;
}

iTunesEmulator.prototype.getSystemSounds = function()
{
if (this.platform == "AppleTV") {
return this._systemSounds;
} else {
// This method only exists on AppleTV
return null;
}
}

iTunesEmulator.prototype._play = function(aTrackList, aTrackNumber)
{
this.pause();
Expand Down
58 changes: 58 additions & 0 deletions emulator/lib/SystemSounds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
function SystemSounds()
{
/* Constants */
this.SystemSoundSelect = 10000;
this.SystemSoundToggle = 10001;
this.SystemSoundScrollStart = 10002;
this.SystemSoundScrollLimit = 10003;
this.SystemSoundExit = 10004;
this.SystemSoundError = 4294965796;

/* Audio Engine */
this._audioEngine = new Audio();
this._audioEngine.style.display = "none";

this._audioEngine.loop = false;
this._audioEngine.volume = 1;

function _initAudioEngine(aContext){
if (document.body) {
document.body.appendChild(aContext._audioEngine);
} else {
setTimeout(_initAudioEngine, 50, aContext);
}
}

_initAudioEngine(this);
}

SystemSounds.prototype.playSystemSound = function(aSystemSound)
{
switch (aSystemSound) {
case this.SystemSoundSelect:
case this.SystemSoundToggle:
this._play("emulator/sounds/Selection.aif");
break;
case this.SystemSoundScrollStart:
this._play("emulator/sounds/SelectionChange.aif");
break;
case this.SystemSoundScrollLimit:
this._play("emulator/sounds/Limit.aif");
break;
case this.SystemSoundExit:
this._play("emulator/sounds/Exit.aif");
break;
case this.SystemSoundError:
default:
break;
}
}

SystemSounds.prototype._play = function(aFile)
{
this._audioEngine.pause();

this._audioEngine.src = window.iTunes._baseURL + aFile;
this._audioEngine.load();
this._audioEngine.play();
}
Binary file added emulator/sounds/Exit.aif
Binary file not shown.
Binary file added emulator/sounds/Limit.aif
Binary file not shown.
Binary file added emulator/sounds/Selection.aif
Binary file not shown.
Binary file added emulator/sounds/SelectionChange.aif
Binary file not shown.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<script language="javascript" type="text/javascript">
// Configure this to point to your own library
var iTunesMusicLibrary = "file://localhost/Users/solitude/Music/iTunes/iTunes%20Music%20Library.xml";
var simulatePlatform = "AppleTV";
</script>
<script src="emulator/iTunesEmulator.js" language="javascript" type="text/javascript"></script>
<!-- - - - - - - - - - - - - - - - - -->
Expand All @@ -22,6 +23,9 @@
// Show what platform we are running on
alert("Emulating iTunes " + window.iTunes.version + " for " + window.iTunes.platform);

var theSystemSounds = window.iTunes.getSystemSounds();
setTimeout("theSystemSounds.playSystemSound(theSystemSounds.SystemSoundScrollLimit);", 1000);

</script>
<!-- - - - - - -->

Expand Down

0 comments on commit 99f572f

Please sign in to comment.