One Player At A Time Please...

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
02Sideman
Posts: 4
Joined: Mon Mar 23, 2009 6:18 pm

One Player At A Time Please...

Post by 02Sideman » Thu Jun 18, 2009 11:41 pm

Hello all -
I'm new to Revolution Studio and can't find a solution to this problem. I'm building a screen that has a list of 5 MP3's. I'm using 5 player objects, but I want to allow only 1 to play at a time. I also want each song to start at it's beginning. Is there a command that I can use for this?

Any help would be greatly appreciated...

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

Post by Klaus » Fri Jun 19, 2009 9:05 am

Hi Sideman (left or right side? ;-))

I would need a bit more info (do the players have the controller visible? do you start them by script?) but why not just use ONE player object and set the filename everytime?

This way you would eliminate all of your probkems at once:
Only one sound at a time and setting the filename will also start the sound from the beginning :-)

BTW to "rewind" (play from start) a player you can:

Code: Select all

...
set the currenttime of player "xyz" to 0
...
Before you start the player.


Best

Klaus

02Sideman
Posts: 4
Joined: Mon Mar 23, 2009 6:18 pm

One Player At a Time please...

Post by 02Sideman » Fri Jun 19, 2009 12:01 pm

Good morning to you Klaus - Hopefully the GOOD side!

I'm a musician and I'm trying to build an interactive discography. Each screen has an image (cover) an album project, and the names of some songs from the album that feature my 5 string bass strugglings. For now, the the songs names are on buttons which in turn, control the corresponding player. The user clicks the button, and gets a 30 second sample of music. The player objects are invisible. I found a way to make it work but it seems a little complicated, I'd love to know how to set the filename each time. Here's an example of one of my button scripts using 3 MP3s:

Code: Select all


-- Script for Button 1
on mouseUp 
   put the label of me into myLabel 
   if myLabel is not "Stop" then 
      set the label of me to "Stop" 
      start player 1
      stop player 2
      set the label of button 2 to "Song 2"
      set the currenttime of player 2 to 0 
      stop player 3
      set the label of button 3 to "Song 3"
      set the currenttime of player 3 to 0  
   else 
      set the label of me to "Song 1" 
      stop player 1 
      set the currenttime of player 1 to 0
      stop player 2 
      set the label of button 2 to "Song 2"
      set the currenttime of player 2 to 0 
      stop player 3
      set the label of button 3 to "Song 3"
      set the currenttime of player 3 to 0 
   end if 
end mouseUp

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

Re: One Player At a Time please...

Post by Klaus » Fri Jun 19, 2009 12:36 pm

Hi Sideman,
02Sideman wrote:Good morning to you Klaus - Hopefully the GOOD side!
Hehe, very good :-)

I am also a musician and play the bass, the world is avillage!
If you like to take a look/hear:
http://www.major-k.de/bass

OK, setting the filename of a player is as simple as it sounds:

Code: Select all

...
  set the filename fo player "xyz" to "path/to/your/soundfile.aif"
...
So I would suggest the following:
Do only use one player ("main_player" in my example script) and set the filename with the different buttons.

I use these names for the buttons (a clever naming convention can save a lot of time and typing!)
Button to play clip 1 = "play_1"
Button to play clip 2 = "play_2"
Button to play clip 3 = "play_3"

The only difference in the scripts of these buttons are the filenames of your sounds:

Button "play_1":

Code: Select all

on mouseup
  lock screen
 ## So the user will not see our tricks ;-)
  
  ## We simply reset all buttons to "Start"!
  repeat with i = 1 to 3
    set the label of btn ("play_" & i) to "Start"
  end repeat
     
  ## First check if sound is playing
  if the label of me = "Stop" then
    
    ## Stop and "reset" player object
    stop player "main_player"
    set the filename of player "main_player" to empty
    set the currenttime of player "main_player" to 0
    
    ## Label was "Start"
  else
    set the label of me to "Stop"
    
    ## Now set the filename, this is the only differnce in the three buttons
    set the filename of player "main_player" to "your filename here..."
    start player "main_player"
  end if
end mouseup
As you can see, with the clever naming convention NO button name or number needs to be in the script and so this script will work for any number of buttons!

Hope that helps!


Best from germany

Klaus

02Sideman
Posts: 4
Joined: Mon Mar 23, 2009 6:18 pm

Post by 02Sideman » Fri Jun 19, 2009 8:14 pm

Thank you so much Klaus :D
My compliments on your bass playing, and it is indeed a pleasure to meet you. I'm going to implement your code into my new demo immediately, and thank you thank you thank you! You can have a listen to what I do as well:

http://www.fromzerotosideman.com/From_Z ... uthor.html

or http://www.melbrown.net/index.php
I'm updating, so you'll have to start at Wayman Tisdale's CDs for samples in the spin doctor section...

BTW would you mind explaining the "lock screen" command?

Be well my new friend -

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

Post by Klaus » Sat Jun 20, 2009 1:03 pm

Hi Mel,
02Sideman wrote:Thank you so much Klaus :D
You're welcome!
02Sideman wrote:My compliments on your bass playing, and it is indeed a pleasure to meet you.
Thank you very much!
I checked your site and happily can return that compliment :-)
02Sideman wrote:BTW would you mind explaining the "lock screen" command?
Be well my new friend -
Yes, although it is not really necessary here, I got used to write a "lock screen" before I start updating any content on the screen.
This way all neccessary screen redraws (like displaying text you put into fields, set the label(s) of button(s) etc.) will only occur AFTER you "fire" a "unlock screen" or after the handler has finished.

If you have LOT of things going on on the screen, then this command will also speed up thing up to the factor 1000! No fooling!
Like if you put thousands of lines into a field in a repeat loop, then this may take many seconds if the screen is NOT locked but only some milliseconds WITH the screen locked!

Have a nice weekend my new friend :-)


Best from germany

Klaus

Post Reply