mobilePlaySoundOnChannel and .wav

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Turtle
Posts: 16
Joined: Thu Nov 30, 2017 6:33 am

mobilePlaySoundOnChannel and .wav

Post by Turtle » Fri Apr 06, 2018 2:04 am

Hello my friends,
long time i was away, hope you doing well !!
So i got a problem playing .wav on desktop and on android. On desktop it makes some noise and on mobile it doesnt make anything. so here is my code

Code: Select all

put tSoundData into URL("binfile:" & tAudioFile)
 if the environment is "mobile" then
      mobilePlaySoundOnChannel tAudioFile, pChannel, "now"
   else
       play audioclip tAudioFile
   
   end if
   
where tSoundData is the .wav file data i get from the database
and tAudioFile is

Code: Select all

specialFolderPath("documents") & "/" & pChannel & ".wav"
what am i doing wrong ? :?:
p.s. i am using livecode 8.1.6

Turtle
Posts: 16
Joined: Thu Nov 30, 2017 6:33 am

Re: mobilePlaySoundOnChannel and .wav

Post by Turtle » Sat Apr 07, 2018 4:47 am

ok...i changed my audio file to .aiff and it worked only for desktop. In mobile the result is "could not play the sound" ....maybe everyone is busy , but little help could be very appreciated ))
Thanks for attention )))

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: mobilePlaySoundOnChannel and .wav

Post by bwmilby » Sat Apr 07, 2018 6:11 am

My guess is that it is a sound format issue. WAV files need to be uncompressed for example (per the dictionary entry). I don't have android, so can't really speak to that specifically.

You may also want to try the "play" command for mobile.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: mobilePlaySoundOnChannel and .wav

Post by bogs » Sat Apr 07, 2018 1:11 pm

Turtle wrote:
Sat Apr 07, 2018 4:47 am
....maybe everyone is busy , but little help could be very appreciated ))
Well, I don't think *everyone* is busy, but sometimes people who might know are :D

I don't do much with sound or mobile, but I dev on Linux for which sound is the bane of your existence, and I don't dev for mobile at all. I hope that you will also mention which OS you are dev'ing on, as sometimes problems are OS specific.

However, I can point you to the things I looked at when I was trying to figure sound out way back when.

Theoretically, there are 3 formats that Lc can work with in the sound realm, either .WAV, .AIFF, or .AU format. Not sure why they settled on those, but I'm sure there was a reason. Myself, I'd have gone with as many formats as possible, or lacking that, ones that are open and/or in wide use, like ogg, mp3, wav is good (good = a format widely used/accessible, not a good as in technical merit).

Not sure if you looked through the Livecode lessons or not, but here is a lesson for playing sound. It includes a section that explains the differences in accessing sound on desktop and mobile.

Hope you find some of the above helpful.
Image

Turtle
Posts: 16
Joined: Thu Nov 30, 2017 6:33 am

Re: mobilePlaySoundOnChannel and .wav

Post by Turtle » Sun Apr 08, 2018 12:29 am

Thanks guys for reply . my OS is windows 7, and i am testing on HTC, Samsung and alcatel. i tried all what you have told me, but guess what ... the problem is from the head )))
is this code correct for creating a folder ?

Code: Select all

 create folder specialfolderpath("documents")&"/audioapp"

well, because the result is "cant create that directory". i tried this way too

Code: Select all

 
 put specialfolderpath("documents")&"/audioapp" into tCopyFolder
   answer tCopyFolder
   create folder tCopyFolder
but no luck.
here i am really confused

Turtle
Posts: 16
Joined: Thu Nov 30, 2017 6:33 am

Re: mobilePlaySoundOnChannel and .wav

Post by Turtle » Sun Apr 08, 2018 3:57 am

i am so sorry, but i really dont understand what is going on, i am fixing one thing and the the other one is not working. so i am closing this topic... all is messed up

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: mobilePlaySoundOnChannel and .wav

Post by bogs » Sun Apr 08, 2018 3:31 pm

Hey Turtle, I have to admit, I'm feeling a bit confused myself. The thread started off with not being able to play sound. Was that part of it resolved?

In your next post, your talking about creating a folder. Here is the entry from Max's wiki. Basically, you can create a folder along any legitimate path, with some exceptions. Android and iOs sandbox some folders (note: I do not develop for mobile, so I am hardly an expert in this area).

Theoretically (I have no way to test this, maybe someone that knows will answer), this should work for creating a folder on android:

Code: Select all

// make sure there are no spaces between the quotes and your path...
create folder (specialFolderPath("documents") & "/audioapp")
A variable could be used to build the path as you did in your second code example, but for a one time shot making something I would just stick with the simpler syntax above.

As for the line 'answer tCopyFolder', this should have told you the path you built, not whether it was created or not. Still, I am curious, what did the answer dialog say when it popped up? Was it correctly built?

To find out whether or not the folder was created, you could check with something like the folders, which is a list of the folders from a particular path.Something like (again, unable to test on mobile, works on desktop) -

Code: Select all

answer folders(specialFolderPath("documents"))
If that doesn't work, please let us know, and we may be able to better help you :)
Image

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: mobilePlaySoundOnChannel and .wav

Post by Klaus » Sun Apr 08, 2018 3:43 pm

If something does not works as it should always check "the result":

Code: Select all

...
create folder (specialFolderPath("documents") & "/audioapp")
if the result <> EMPTY then
  answer "Error:" && the result
end if
...
EMPTY means success, otherwise that might give you (and us) a clue why it does not work.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: mobilePlaySoundOnChannel and .wav

Post by bogs » Sun Apr 08, 2018 4:04 pm

Good tip Klaus! I keep forgetting about that one :?
Image

Turtle
Posts: 16
Joined: Thu Nov 30, 2017 6:33 am

Re: mobilePlaySoundOnChannel and .wav

Post by Turtle » Sun Apr 08, 2018 5:43 pm

Hey bogs , hey Klaus thank you for your tips. i really need to take a deep breath and concentrate )) ok i got the creating folder, i dont know why but this way

Code: Select all

 
 set the defaultfolder to specialFolderPath("Documents")
  ---create a folder to put the files in there
   create folder "audioapp"
well that the result thing is really very helpful, as i see that i do not have any problem with my database. what is not working is the playing the sound. i am testing on android phones . i found this http://livecode.byu.edu/audio/audioplayback-mobile.php where it says what format to use for android. i have tried all but it simply does not sound anything and the result is empty. here is what i tried

Code: Select all

 
 put revQueryDatabase (gMediaDBID,"select soundData from sounds where soundID ='" & pID & "'") into tCursor
   answer the result, tCursor
   put revDatabaseColumnNamed(tCursor, "soundData", "tSound") into tErrorMsg
   
   put "audioapp/" & pChannel & ".aac" into tAudioFile
   
    put tSound into URL("binfile:" & tAudioFile)
   ........
   mobilePlaySoundOnChannel tAudioFile, pChannel, "now"
       answer the result
       
       .......
       play tAudioFile
       answer the result
   
i get the tCursor and the result any number, no error msg and for playing the results are empty

forget to add, tSound has the data, it is not empty

Turtle
Posts: 16
Joined: Thu Nov 30, 2017 6:33 am

Re: mobilePlaySoundOnChannel and .wav

Post by Turtle » Mon Apr 09, 2018 8:22 pm

holly .... OMG i get it working!!! auuuu :D :D :D well after killing myself million times i found this http://forums.livecode.com/viewtopic.ph ... 0&start=15, where
newtronsols wrote:
Sun Oct 26, 2014 7:36 am
Another useful tip is: wait until the sound is done
i want to kiss him/her for the useful tip.
and you know why it helped me? because my code is in a function where at the end there is

Code: Select all

return blablabla
and as i am understanding, it wasnt waiting until the sound be played and finishing the function without starting? well i dont know this but my problem SOLVED. oh, and i did with mp3 format, well i will try the other formats too, and i will see which one is lighter to choose.

Turtle
Posts: 16
Joined: Thu Nov 30, 2017 6:33 am

Re: mobilePlaySoundOnChannel and .wav

Post by Turtle » Mon Apr 09, 2018 8:42 pm

THANKS EVERYONE. :D :D

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: mobilePlaySoundOnChannel and .wav

Post by bogs » Mon Apr 09, 2018 10:41 pm

Congrats on figuring it out Turtle :D
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”