Player can't 'see' external audio file on all computers
Posted: Thu May 21, 2015 8:17 pm
Summary: I link an external audio file to a player. Everything works fine unless I move it to another computer. Then the player is 'dead'.
I have a stack that is located inside the folder 'TestPlayer2'. There is a sub-folder called 'AudioFolder' also located inside the main folder 'TestPlayer2'. Inside the sub-folder, 'AudioFolder', is an mp3 audio file.
The stack has a button with a script that creates a player and links it to the external audio file in the folder 'AudioFolder'.
The script works fine and the player plays the audio file with no problems.
The problem occurs when I create the player, link the external file, and then move the folder 'TestPlayer2' to another computer. When I click on the player on the second computer, the sound doesn't play.
I'm using a default folder and relative path name as I understand the concept. Apparently something in my knowledge is missing.
I understand that when you move files to another computer, the path name changes in the first few nodes. However, the path name starting with 'TestPlayer2' should be the same on every computer: " ../TestPlayer2/AudioFolder/myaudiofile.mp3"
In the stack script I establish a defaultFolder with the following script:
---------------------------------------------------------
on preOpenStack
set itemDel to "/"
set the defaultFolder to item 1 to -2 of (the effective fileName of this stack)
end preOpenStack
--------------------------------------------------------------------------
The button that creates the player and associates it with the external mp3 file has the following script:
----------------------------------------------------------
on mouseUp
set the itemDelimiter to "/"
answer file "Pick a file" --PROMPT TO SELECT THE AUDIO FILE IN THE SUB-FOLDER, "AudioFolder"
put it into fld "textAudioFilename" --PUTS THE COMPLETE PATH NAME OF 'IT' INTO A FIELD
---THE FOLLOWING 3 STEPS MODIFY THE COMPLETE PATHNAME BY STRIPPING OUT THE FIRST FEW STEPS UNIQUE TO EACH COMPUTER-----
put item -3 to -1 of fld "textAudioFilename" into fld "textAudioFilename" --REMOVES STEPS IN PATH PREVIOUS TO FOLDER 'TestPlayer2
put "../" before first char of fld "textAudioFilename" --ADDS "../" BEFORE PATH NAME TO POINT TO PREVIOUS STEPS ON PATH
put fld "textAudioFilename" into theFileToPlay --PUTS CONTENTS OF FLD "textAudioFilename" INTO A VARIABLE
---------------------------------------------------------------------------------------------------------------------------------------------------------
create player "jokeAudio" --CREATES THE PLAYER
set the filename of player "jokeaudio" to theFiletoPlay --LINKS PLAYER TO EXTERNAL AUDIO FILE
----------SETS PLAYER PROPERTIES-----------------
set the showcontroller of player "jokeAudio" to true
set the height of player "jokeAudio" to 26
set the width of player "jokeAudio" to 200
set the loc of player "jokeAudio" to 200,200
show player "jokeAudio"
end if
end mouseUp
----------------------------------------------------------------------------------------------
What am I missing so that the player will 'see' the external audio file on any computer?
Thanks!!
I have a stack that is located inside the folder 'TestPlayer2'. There is a sub-folder called 'AudioFolder' also located inside the main folder 'TestPlayer2'. Inside the sub-folder, 'AudioFolder', is an mp3 audio file.
The stack has a button with a script that creates a player and links it to the external audio file in the folder 'AudioFolder'.
The script works fine and the player plays the audio file with no problems.
The problem occurs when I create the player, link the external file, and then move the folder 'TestPlayer2' to another computer. When I click on the player on the second computer, the sound doesn't play.
I'm using a default folder and relative path name as I understand the concept. Apparently something in my knowledge is missing.
I understand that when you move files to another computer, the path name changes in the first few nodes. However, the path name starting with 'TestPlayer2' should be the same on every computer: " ../TestPlayer2/AudioFolder/myaudiofile.mp3"
In the stack script I establish a defaultFolder with the following script:
---------------------------------------------------------
on preOpenStack
set itemDel to "/"
set the defaultFolder to item 1 to -2 of (the effective fileName of this stack)
end preOpenStack
--------------------------------------------------------------------------
The button that creates the player and associates it with the external mp3 file has the following script:
----------------------------------------------------------
on mouseUp
set the itemDelimiter to "/"
answer file "Pick a file" --PROMPT TO SELECT THE AUDIO FILE IN THE SUB-FOLDER, "AudioFolder"
put it into fld "textAudioFilename" --PUTS THE COMPLETE PATH NAME OF 'IT' INTO A FIELD
---THE FOLLOWING 3 STEPS MODIFY THE COMPLETE PATHNAME BY STRIPPING OUT THE FIRST FEW STEPS UNIQUE TO EACH COMPUTER-----
put item -3 to -1 of fld "textAudioFilename" into fld "textAudioFilename" --REMOVES STEPS IN PATH PREVIOUS TO FOLDER 'TestPlayer2
put "../" before first char of fld "textAudioFilename" --ADDS "../" BEFORE PATH NAME TO POINT TO PREVIOUS STEPS ON PATH
put fld "textAudioFilename" into theFileToPlay --PUTS CONTENTS OF FLD "textAudioFilename" INTO A VARIABLE
---------------------------------------------------------------------------------------------------------------------------------------------------------
create player "jokeAudio" --CREATES THE PLAYER
set the filename of player "jokeaudio" to theFiletoPlay --LINKS PLAYER TO EXTERNAL AUDIO FILE
----------SETS PLAYER PROPERTIES-----------------
set the showcontroller of player "jokeAudio" to true
set the height of player "jokeAudio" to 26
set the width of player "jokeAudio" to 200
set the loc of player "jokeAudio" to 200,200
show player "jokeAudio"
end if
end mouseUp
----------------------------------------------------------------------------------------------
What am I missing so that the player will 'see' the external audio file on any computer?
Thanks!!