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 » Mon Apr 11, 2011 5:15 pm

Thanks to Bernd and Klaus, I've finished my "callbacks":

Code: Select all

on openCard
   resetNarrationWordColor
 putLine 1
   show field "Narration"
   playTransient "Page6Narration.wav"
   --Convert the times from callback time units to ms
        send "changeNarrationWordColor 1" to me in 1*1.6667 milliseconds
         send "changeNarrationWordColor 2" to me in 364*1.6667 milliseconds
         send "changeNarrationWordColor 3" to me in 587*1.6667 milliseconds
         send "changeNarrationWordColor 4" to me in 890*1.6667 milliseconds
         send "changeNarrationWordColor 5" to me in 984*1.6667 milliseconds
         send "changeNarrationWordColor 6" to me in 1143*1.6667 milliseconds
         send "changeNarrationWordColor 7" to me in 1359*1.6667 milliseconds
         send "changeNarrationWordColor 8" to me in 1447*1.6667 milliseconds
         send "changeNarrationWordColor 9" to me in 1505*1.6667 milliseconds
         send "changeNarrationWordColor 10" to me in 1708*1.6667 milliseconds
   
   send "putLine 2" to me in 2256*1.6667 milliseconds
         send "changeNarrationWordColor 1" to me in 2257*1.6667 milliseconds
         send "changeNarrationWordColor 2" to me in 2367*1.6667 milliseconds
         send "changeNarrationWordColor 3" to me in 2529*1.6667 milliseconds
         send "changeNarrationWordColor 4" to me in 2716*1.6667 milliseconds
         send "changeNarrationWordColor 5" to me in 3134*1.6667 milliseconds
         send "changeNarrationWordColor 6" to me in 3415*1.6667 milliseconds
   
   send "putLine 3" to me in 3561*1.6667 milliseconds
         send "changeNarrationWordColor 1" to me in 3562*1.6667 milliseconds
         send "changeNarrationWordColor 2" to me in 3729*1.6667 milliseconds
         send "changeNarrationWordColor 3" to me in 3798*1.6667 milliseconds
         send "changeNarrationWordColor 4" to me in 4048*1.6667 milliseconds
         send "changeNarrationWordColor 5" to me in 4162*1.6667 milliseconds
         send "changeNarrationWordColor 6" to me in 4514*1.6667 milliseconds
         send "changeNarrationWordColor 7" to me in 4686*1.6667 milliseconds
         send "changeNarrationWordColor 8" to me in 4746*1.6667 milliseconds
         send "changeNarrationWordColor 9" to me in 5101*1.6667 milliseconds
         send "changeNarrationWordColor 10" to me in 5295*1.6667 milliseconds
         send "changeNarrationWordColor 11" to me in 5481*1.6667 milliseconds
         send "changeNarrationWordColor 12" to me in 5575*1.6667 milliseconds
         send "changeNarrationWordColor 13" to me in 5920*1.6667 milliseconds
   send "resetNarrationWordColor" to me in 6500*1.667 milliseconds
end openCard
In the stack script:

Code: Select all

on playTransient audioFile
         if the environment is "mobile" then
         iphonePlaySoundOnChannel audioFile, "Transient", "now"
      else play audioFile
end playTransient

Code: Select all

on putLine pLine
   put line pLine of field "TextSource" into field "Narration"
end putLine

Code: Select all

on changeNarrationWordColor pWord
   resetNarrationWordColor
   set the textColor of word pWord of field "Narration" to "green"
end changeNarrationWordColor
To get the original player callback times,I have a button on the card with the script:

Code: Select all

on mouseUp
   set the playRate of player "Narration" to 0.3
   start player "Narration"
end mouseUp
I have this in the message box:

Code: Select all

 set the paused of player "Narration" to not the paused of player "Narration";put the currentTime of player "Narration""
After I have all the callbacks, I'll delete the player.

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 11, 2011 5:57 pm

Hi Britt,

I am glad this works for you.

If you want the listener/reader to be able to pause the narration then you would probably not fire all the callbacks at once.

But that is for version 2.0 :)

Kind regards

Bernd

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

Re: Sound playback driving me crazy...

Post by Brittgriscom » Mon Apr 11, 2011 6:45 pm

How would I integrate pause/restart capability?

Edit: Actually, I don't think I need that. I'll post a stop/restart-from-beginning functionality in a bit.

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

Re: Sound playback driving me crazy...

Post by Brittgriscom » Mon Apr 11, 2011 9:14 pm

Here is the stop/restart-from-beginning code:

In field "Narration" script:

Code: Select all

on mouseUp
   if iPhoneSoundChannelStatus(Transient) is playing then--Not sure how to do this for the desktop version as well
   stopChannel "Transient"
   stopMessages
   resetNarrationWordColor
else send "openCard" to me in 1 millisecond
end mouseUp
In stack script:

Code: Select all

on stopMessages
        repeat for each line aLine in the pendingMessages
            if aLine contains "NarrationWordColor"  then 
                  cancel item 1 of aLine
            end if
        if aLine contains "putLine"  then 
                  cancel item 1 of aLine
            end if
      end repeat
end stopMessages

on stopChannel pChannel
   if the environment is "mobile" then
      iphoneStopPlayingOnChannel pChannel
   else play empty
end stopChannel

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 11, 2011 10:04 pm

Hi Britt,

this is a little involved since I just noticed that you would have to use a movie player. the movie player on iOS can give you the currenttime if you ask it. You would need to rewrite your script a whole lot.

I propose that you think how important that is for your project. And if you think it is important for the 1.0 version lets start a new thread.

I posted
http://forums.runrev.com/phpBB2/viewtop ... 229#p33178
a little sample stack that shows the use of the movie player. I tried and was able to play a sound file .3gp. You would have to test your file and probably set the visible of the play to false.

Kind regards

Bernd

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Sound playback driving me crazy...

Post by Jellicle » Tue Apr 12, 2011 7:42 am

bn wrote:Hi, today I tested the iphonePlaySoundOnChannel syntax on my iPhone. It does what you expect: if you put the app to sleep with the sleep button and the sound is playing and then start the iPhone again the sound plays on.
It just does not work for the simple play command.
Bernd
Using play or iphonePlaySoundOnChannel makes no difference for me - the mp3 stops playing when that button is pressed. No other iOS app I have that plays mp3s does that - they all keep playing the sound. I *want* the sound to keep playing.

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

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 » Tue Apr 12, 2011 11:05 am

Hi Jellicle,
I *want* the sound to keep playing
I append a stack that does what you want on my iPhone. It resumes the sound when waking up the iPhone.
It uses iphonePlaySoundOnChannel syntax. Maybe I was not clear in my previous post.

Have a look

Kind regards

Bernd
Attachments
playChannel.zip
(69.89 KiB) Downloaded 278 times

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Sound playback driving me crazy...

Post by Jellicle » Tue Apr 12, 2011 2:26 pm

Perhaps I'm not being clear. I do not want the sound to stop playing when the hardware sleep button is pressed. I want it to keep playing. You seem to think I want something different :)
14" MacBook Pro
Former LiveCode developer.
Now recovering.

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

Re: Sound playback driving me crazy...

Post by Klaus » Tue Apr 12, 2011 3:05 pm

Hi Jellicle,

I think LiveCode iOS is NOT able to be a "background application" that will be the problem!
Know what I mean?


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 » Tue Apr 12, 2011 3:11 pm

Hi Jellicle,
I do not want the sound to stop playing when the hardware sleep button is pressed. I want it to keep playing. You seem to think I want something different
Sorry, I finally got it. Well, I think that is something for a bug report. I don't know if you have access to the Quality Control Center. If yes that would be the place, if no just report to support at runrev.com

Klaus wrote:
I think LiveCode iOS is NOT able to be a "background application" that will be the problem!
If that is the case then make it an enhancement request.

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 12, 2011 6:20 pm

I figured out how to stop/restart-from-beginning the sound in iOS. Can someone tell me how to do it in the desktop version of livecode (without using a player object)?

That is, if the sound is playing and the field is clicked, I want the sound to stop. If the sound is not playing, I want it to start from the beginning.

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

Re: Sound playback driving me crazy...

Post by Klaus » Tue Apr 12, 2011 6:30 pm

Hi Britt,

something like this should work:

Code: Select all

on mouseup
  ## 1. Check if a sound is playing
  ## Sound is NOT playing:
  if the sound is "done" then

   ## PLAY "file to play" will always start from the beginning!
    play ac "path to your sound file here"
  else

   ## Stop the playback
    play stop
 end if
end mouseup
Check "play" in the dictionary to get more info!


Best

Klau

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

Re: Sound playback driving me crazy...

Post by Brittgriscom » Tue Apr 12, 2011 7:59 pm

Thanks Klaus.

Here is my stop/restart code in the script for my "Narration" field for both the desktop and ios:

Code: Select all

on mouseUp
   if the environment is "mobile" then
      if iPhoneSoundChannelStatus(Transient) is playing then
         stopChannel "Transient"
      else send "openCard" to me in 1 millisecond
      
   else
        if the sound is "done" then
             openCard
      else stopChannel "Transient"
   end if
end mouseUp
Here is the handler in the stack script:

Code: Select all

on stopChannel pChannel
   if the environment is "mobile" then
      iphoneStopPlayingOnChannel pChannel
   else play empty
   stopMessages
   resetNarrationWordColor
end stopChannel

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

Re: Sound playback driving me crazy...

Post by Klaus » Tue Apr 12, 2011 8:34 pm

Brittgriscom wrote:

Code: Select all

on stopChannel pChannel
  ...
   else play empty
  ...
end stopChannel
play STOP 8)

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Sound playback driving me crazy...

Post by Jellicle » Wed Apr 13, 2011 6:40 am

Klaus wrote:Hi Jellicle,

I think LiveCode iOS is NOT able to be a "background application" that will be the problem!
Know what I mean?
Putti the screen to sleep does not put the app into the background, so that's not the issue :)
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Post Reply