Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
on PlaySound pSound
if pSound is empty or pSound is "pSound" then put "wine_glasses_x2_clink_004.mp3" into pSound
set the itemDel to "/"
put item 1 to -2 of (the fileName of this stack) into tSoundFile
put "/sound files/" & pSound after tSoundFile
if the environment is "mobile" then
mobilePlaySoundOnChannel tSoundFile, "current", "now"
else
play tSoundFile
end if
end PlaySound
On desktop a static noise comes out of the speakers for 2 seconds (length of audio file)
On android nothing happens.
The folderpath is correct. The file suffix is correct. The folder "sound files" is included in the standalone application settings under "included files and folders".
Any ideas?? Thanks for your help guys!
-Will
Last edited by William Jamieson on Thu Dec 18, 2014 7:30 pm, edited 1 time in total.
Ok so it turns out the the two styles give the equivalent result
put specialFolderPath("engine") into tFile
and
set the itemdel to "/"
put item 1 to -2 of the filename of this stack into tFile
So I am back to where I started. There is something that I am missing but I still dont know what.
I also made sure that the folder "sound files" was attached and it is there when deployed. I hope I am clear as to what the issue is because I feel like this is really basic but I am just missing it by a hair. Please enlighten me.
You have a couple of choices. You can convert the mp3 to either an aif or wav file and import it as a control. Then the "play" command will work. You won't need to use a file path this way, just the short name of the sound. If this is just a short sound effect, this method works very well.
If the file is larger then you should use a player object. To load the player, you set its filename to the file path of the sound file. To start the playback, use the "start" command. Assuming your filepath is correct and named "tSoundFile" and you have a player named "sndPlayer" then something like this:
set the filename of player "sndPlayer" to tSoundFile
if the result is not empty then answer the result -- just a check to see if it worked
start player "sndPlayer"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Ok Great! Thanks Jacque! That definitely worked on Desktop.
I also found the solution for mobile as well. The difference is that Andoid cares whether the letters are capitalized or not. I am not used to checking capitalization but it seems to be a crucial step when working with Android.
What I did to make sure that the file I wanted would play without having to worry about capitalization was
on PlaySound pSound
if the environment is not "mobile" then exit PlaySound
put specialfolderpath("engine") & "/Sound Files" into tFolder
set the defaultfolder to tFolder
put "/" & line pSound of the files after tFolder
mobilePlaySoundOnChannel tFolder, "current", "now"
end PlaySound
where pSound is the line of the sound I wish to choose which I know beforehand**
William Jamieson wrote:I also found the solution for mobile as well. The difference is that Andoid cares whether the letters are capitalized or not. I am not used to checking capitalization but it seems to be a crucial step when working with Android
IOS and Linux too. For consistency I always match the case when creating file paths, just to be sure.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Ahh got it. Thanks Jacque. I will take note of that. Especially as the app I am developing currently will be for bot Android and iOS. Will start working on the iOS version now.