Sound playback driving me crazy...

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: Sound playback driving me crazy...

Post by Brittgriscom » Wed Mar 30, 2011 8:01 pm

I think I found the problem. This works in the sim, but not in LC:

on mouseUp
put specialFolderPath("engine") & "/Page1.wav" into tWholePath
play tWholePath
end mouseUp

This works in LC, but not in the sim:

on mouseUp
put specialFolderPath("engine") & "Page1.wav" into tWholePath
play tWholePath
end mouseUp

The difference is the "/" before the name of the sound file.
So how do we adjust our code so that it works in both?

Edit: I see you just answered that. How would we make this adjustment for all our sound files, including player objects and audioclips, rather than just for a single file?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sound playback driving me crazy...

Post by bn » Wed Mar 30, 2011 8:23 pm

Hi Britt,

now add a field "fAllFiles" to the card and change the code of the first button to

Code: Select all

on mouseUp
   if the environment is "mobile" then
      put specialFolderPath("engine") & "/soundFolder/samoashort.3gp" into tWholePath
      play tWholePath
   else
      put the effective fileName of this stack into tWholePath
      put tWholePath
      set the itemdelimiter to "/" 
      put  "/soundFolder/samoashort.3gp" into last item of tWholePath
      
      -- get a list of all files in the "soundFolder" folder 
      put the defaultFolder into tOldDefaultFolder -- store the defaulfFolder
      set the defaultFolder to item 1 to -2 of tWholePath
      put the files into tAllFilesOfTheFolder
      filter tAllFilesOfTheFolder without ".*" -- filter out invisible system files that start with .
      put tAllFilesOfTheFolder into field "fAllFiles"
      set the defaultFolder to tOldDefaultFolder -- lets be nice and restore the defaultFolder
      
      set the filename of player "p1" to tWholePath
      start player "p1"
   end if
end mouseUp
it gives you all the files in the folder soundFolder. From there you could play them. Just substitute the filenames in the paths. like in

Code: Select all

set the itemDelimiter to "/"
put line xyz of field "fAllfiles" into last item of tWholepath
Of course you would have to store tWholePath somewhere.

have a look at the comments and look up unfamiliar terms in the dictionary or ask here.

Kind regards

Bernd

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: Sound playback driving me crazy...

Post by Brittgriscom » Wed Mar 30, 2011 8:46 pm

I don't understand much of that yet, but I will try to.

I tried this for an individual file:

on openCard
   if the environment is "mobile" then
      put specialFolderPath("engine") & "/Page1.wav" into tWholePath
   else
      put specialFolderPath("engine") & "Page1.wav" into tWholePath
   end if
      set the filename of player "Narration" to tWholePath
play player "Narration"
end openCard

It worked in LC, but not in the sim. Any ideas why?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sound playback driving me crazy...

Post by bn » Wed Mar 30, 2011 9:03 pm

Hi Britt,

are you shure iOS supports wav? I just tried a .wav file and it did not play in the simulator.

Why don't you try an 3gp file. Then you know with the script I provided that they work in both environments. You get your paths straight and then tackle the sound format problem.

Kind regards

Bernd

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Sound playback driving me crazy...

Post by Danny » Wed Mar 30, 2011 10:15 pm

Hey Bernd,
Sorry for the pause between posts.

I have quite a mystery for you. I have been going crazy trying to figure out how to make sound happen in my app. After a couple days I came back to forums and decided to covert my .aiff file to 3gp and that didn't work, or so I thought. Well I knew that your stack worked after I tried it so I copied my button to your stack and entered in the correct path. Well I put it in the simulator and IT WORKED. But I double checked my paths in my app and they were the same but mine wasn't playing in the sim. Once I got the right path I didn't change it.
Do you know why that would be happening? I feel so close but I think it might be something really simple.

Thanks,

Danny

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sound playback driving me crazy...

Post by bn » Wed Mar 30, 2011 10:25 pm

Danny,

could you post your code?

Since scripts can fail silently on iOS/Simulator it is a good idea to add a temporary field to the card(s) called "fErr"
In the stack script you put a handler

Code: Select all

on errorDialog
   put the params into field "fErr"
end errorDialog
if there is anything in the field then you know something is going wrong with your scripts. The error message is not all that clear but it gives you an idea.

Try this and see if another error is preventing the script to run in your app.

Kind regards

Bernd

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Sound playback driving me crazy...

Post by Danny » Thu Mar 31, 2011 4:32 am

Hey Bernd,
Fortunately and unfortunately there were no errors. I'm really stumped.
This is the code in my button. This DOES work in your stack.

Code: Select all

on mouseUp
   put specialFolderPath("engine") & "/Sound/Bite.3gp" into tWhole
play tWhole
end mouseUp
And here are some screen shots of the paths.

The first one is in "Copy Files" of your stack and the other is my stack (I used your button to test my app but that didn't work either)
I did notice that I seemed to get different paths on different stacks so that might be the case but I wasn't able to get identical paths. Your stack and my button played in the simulator but not in LC. That doesn't bother me at all I just wasn't sure if that would be a clue.

Thanks,

Danny
Attachments
Screen shot 2011-03-30 at 11.18.18 PM.png
Screen shot 2011-03-30 at 11.18.18 PM.png (8.8 KiB) Viewed 8747 times
Screen shot 2011-03-30 at 11.17.05 PM.png
Screen shot 2011-03-30 at 11.17.05 PM.png (9.3 KiB) Viewed 8747 times

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Sound playback driving me crazy...

Post by Klaus » Thu Mar 31, 2011 12:34 pm

Hi Britt and all,
Brittgriscom wrote:

Code: Select all

on opencard
      if the environment is "mobile" then
            put specialFolderPath("engine") & "/Page1.wav" into tWholePath
      else
             put specialFolderPath("engine") & "Page1.wav" into tWholePath
      end if
         set the filename of player "Narration" to tWholePath
   play player "Narration"
end openCard
It worked in LC, but not in the sim. Any ideas why?
specialfolderpath("engine") is "specially" designed for Mobile operating systems
and returns NOTHING (= EMPTY) in the desktop version/IDE!
And no error fortunately!

That means that:
...
put specialFolderPath("engine") & "Page1.wav" into tWholePath
...
will result in: Page1.wav
in the IDE! That's why this does work in the IDE!

Now if this does not work in the sim, then it might be a sound format problem,
as Bernd already pointed out.

P.S.
Seeing is believing so I heavily recommend to let you ANSWER your variables
that do not work as exspected!

Code: Select all

on opencard
      if the environment is "mobile" then
            put specialFolderPath("engine") & "/Page1.wav" into tWholePath
      else
             put specialFolderPath("engine") & "Page1.wav" into tWholePath
      end if

        ANSWER tWholePath
       ## now you can see the content of tWholePath!
        ## GUESSING is no replacement for debugging!

         set the filename of player "Narration" to tWholePath
   play player "Narration"
end openCard

Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sound playback driving me crazy...

Post by bn » Thu Mar 31, 2011 4:57 pm

@Danny,

what version of Livecode are you using?

There is a bug in pre 4.6 in Livecode that puts a ASCII 202 into text/code copied from e.g. this forum when on a Mac. If you have copy/pasted code from various sources it just maybe that this one caught you.
The code will work in the IDE/Livecode but will fail on the Simulator/iOS device.

In 4.6 the ASCII 202 is still there but does not stop the code from working in iOS. Bug#9433

The remedy is to either paste the text into a texteditor like the free TextWrangler and do a convert to ASCII there and copy it back into the ScriptEditor. In TextWrangler you can also display hidden characters and you could tell if there are stray characters in the spaces to the left of the code.
Alternatively you could retype the pasted code in the ScriptEditor.

if you want to you can send me your stack and I will have a look at it if I can find anything in particular.

make a button and set the script of that button to:

Code: Select all

on mouseUp
   put "110,105,103,103,101,109,97,110,110,64,117,110,105,45,119,104,46,100,101" into tData
   set the itemDelimiter to ","
   repeat with i = 1 to the number of items of tData
      put numToChar (item i of tData) after tOut
   end repeat
   put tOut
end mouseUp
it will put the address into the message box

Kind regards

Bernd

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Sound playback driving me crazy...

Post by Danny » Fri Apr 01, 2011 9:39 pm

I'm running the 4.6 public release. I sent you the stack.

Thanks,

Danny

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: Sound playback driving me crazy...

Post by Danny » Sat Apr 02, 2011 12:13 am

So thanks to Bernd, I figured out what was going on with my app. I have two Main Stacks and I had only added the sound file to one of the two because I thought didn't have to. Well I did need to and once I did it was working like a champ. The 3gp format does lower the sound quality (to me personally) quite a bit, but use it until you have it working and then experiment with other formats.

I hope this will help you out. Let me know if you have any questions and i'll answer them to the best of my ability.

Danny

dburdan
Posts: 104
Joined: Fri Jan 28, 2011 5:39 am

Re: Sound playback driving me crazy...

Post by dburdan » Sat Apr 02, 2011 6:59 pm

Have you tried the .ogg format? Most AppStore apps use it in their apps.

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: Sound playback driving me crazy...

Post by Brittgriscom » Mon Apr 04, 2011 9:47 pm

Code: Select all

on mouseUp
      if the environment is "mobile" then
            put specialFolderPath("engine") & "/soundFolder/samoashort.3gp" into tWholePath
      --      Why doesn't this work?
      --      set the fileName of player "p1" to tWholePath
       --     start player "p1"
            play tWholePath
            answer tWholePath
      else
Bernd, I got your code to work, but I want both LC and the sim to play players. I don't understand why I can't change the code for the sim to the above. According to the answer dialogue box, it seems to have the right file.

Edit: play player "p1" doesn't work either

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4166
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sound playback driving me crazy...

Post by bn » Mon Apr 04, 2011 11:18 pm

Britt,

it does not work because the iOS does not use a player object to play sounds.
Please have a look at the iOS Release Notes under the Help menu.

change your code to

Code: Select all

on mouseUp
   if the environment is "mobile" then
      put specialFolderPath("engine") & "/soundFolder/samoashort.3gp" into tWholePath
      --      Why doesn't this work?
      --      set the fileName of player "p1" to tWholePath
      --     start player "p1"
      play tWholePath
      answer tWholePath
   else
      put the effective filename of this stack into tPathToMe -- this gets the path to this stack
      set the itemdelimiter to slash
      delete last item of tPathToMe -- delete the name of the stack

      -- put the folder and file path after the path to the stack. Only works if the folder is at the same level as the stack
      put tPathToMe & "/soundFolder/samoashort.3gp" into tWholePath 
      set the fileName of player "p1" to tWholePath
      start player "p1"
   end if
end mouseUP
and the stopPlay button to

Code: Select all

on mouseUp
   if the environment is "mobile" then
      play empty
   else
      stop player "p1"
   end if
end mouseUp
make shure you have a player named "p1" on the card

Now the samoashort.3gp file plays in Livecode and the Simulator.

Kind regards

Bernd

Brittgriscom
Posts: 95
Joined: Wed Mar 30, 2011 10:15 am

Re: Sound playback driving me crazy...

Post by Brittgriscom » Tue Apr 05, 2011 1:52 am

So then I can't do callbacks? How do I highlight the words of my storybook app as they are read?

Post Reply