Permalink
Browse files

Added a new "simulatePlatform" value which can be used to select whic…

…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...
1 parent aa271e0 commit 99f572f3666fd685d8d7e108346e70d4e3aaccb4 @Solitude committed Nov 9, 2009
View
@@ -1,4 +1,5 @@
include("emulator/lib/Library.js");
+include("emulator/lib/SystemSounds.js");
include("emulator/lib/Playlist.js");
function iTunesEmulator(iTunesMusicLibraryURL)
@@ -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;
@@ -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";
@@ -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();
@@ -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();
+}
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -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>
<!-- - - - - - - - - - - - - - - - - -->
@@ -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>
<!-- - - - - - -->

0 comments on commit 99f572f

Please sign in to comment.