WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-25-2009, 06:30 AM
mrvr mrvr is offline
Member
 
Join Date: Dec 2008
Posts: 4
array problem

Hello!
I have made a playlist of songs, which in fact is an array, and I am trying to play the songs by using a for loop (I want to have constantly music at the background).

The problem is that it plays all the songs at once and as I can understand a timer that expires very quickly (I use this timer for the joystick) is responsible for that. I think I have to use another timer, but I have no idea what expiration time it should have, how many repeats, when to start it etc.

Can you give me any suggestions before I send my code?

Thanks
Maria
Reply With Quote
  #2  
Old 02-25-2009, 10:41 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Here is an example script that uses the viztask module to loop through a playlist of songs. Let me know if anything is unclear.
Code:
import viz
import viztask
viz.go()

PLAYLIST = ['crash.wav','BOING!.WAV','quack.wav']

def PlayMusicTask(songs):
	"""Task that loops through a playlist of songs"""
	
	#Preload all songs
	songCycle = viz.cycle([ viz.addAudio(filename) for filename in songs ])
	
	#Loop indefinitely through song list
	while True:
		
		#Play next song
		song = songCycle.next()
		song.play()

		#Wait for song to end
		yield viztask.waitMediaEnd(song)

#Schedule music task
viztask.schedule( PlayMusicTask(PLAYLIST) )
Reply With Quote
  #3  
Old 02-25-2009, 04:46 PM
mrvr mrvr is offline
Member
 
Join Date: Dec 2008
Posts: 4
Thanks for the quick reply (you've saved me a lot of time!)

The only unclear thing is the following line:

songCycle = viz.cycle([ viz.addAudio(filename) for filename in songs ])

It will load the songs as it is or I have to change something? (ie replace the "filename" with the first (actual) filename in songs?)

I also met another problem. I had these errors when I run the code:

Traceback (most recent call last):
File "C:\Program Files\WorldViz\Vizard30\python\viztask.py", line 685, in _onupdate
self._tasks = [ t for t in self._tasks if not t.update() ]
File "C:\Program Files\WorldViz\Vizard30\python\viztask.py", line 652, in update
val = self.__stack[-1].next()
File "museum.py", line 78, in PlayMusicTask
songCycle = viz.cycle([ viz.addAudio(filename ) for filename in songs ])
File "C:\Program Files\WorldViz\Vizard30/python\viz.py", line 7524, in addAudio
return VizAudio(_ipcSend(_VIZ_ADDAUDIO,0,0,fileName,0.0,0 .0,0.0,0.0),**kw)
TypeError: message must be a string
Reply With Quote
  #4  
Old 02-26-2009, 12:18 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Did you get that error by running the exact code I posted?

That line of code creates a cycle of audio objects from the file names. All you have to change is the PLAYLIST variable to contain all the filenames of songs you want to play.
Reply With Quote
  #5  
Old 02-27-2009, 06:25 PM
mrvr mrvr is offline
Member
 
Join Date: Dec 2008
Posts: 4
It was the exact code! The only different thing was the PLAYLIST, where I had replaced the sounds with my songs :-)
Reply With Quote
  #6  
Old 03-02-2009, 09:21 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
So it wasn't the exact code? I'm assuming you incorrectly defined the PLAYLIST variable. I can't provide anymore help unless you post the code you are using.
Reply With Quote
  #7  
Old 03-03-2009, 03:35 AM
mrvr mrvr is offline
Member
 
Join Date: Dec 2008
Posts: 4
You were right. I fixed the problem.
Thanks a lot for your help and time!
Reply With Quote
  #8  
Old 03-07-2014, 07:34 AM
NicoleVR NicoleVR is offline
Member
 
Join Date: Nov 2013
Posts: 3
Only cycle through once?

Hello, the code you helped with here has a loop to indefinetly loop through the songs. What if i want the loop to go through each element in the array only once? is there a way to detect that?

Thanks,

Nicole
Reply With Quote
  #9  
Old 03-10-2014, 09:20 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,453
Since you're not going to cycle through the songs you could use a standard list and a for loop:
Code:
#Preload all songs
songList = [ viz.addAudio(filename) for filename in songs ]

for song in songList:
	
	song.play()
	#Wait for song to end
	yield viztask.waitMediaEnd(song)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A Little Programming Problem with MultiDimensional Arrays shivanangel Vizard 2 04-25-2007 12:21 PM
5DT Data Glove 5 Ultra Problem bjgold Vizard 1 08-08-2006 04:08 PM
problem with female animations vmonkey Vizard 1 10-07-2005 10:36 AM
Copy objects in an array to another array Johannes Vizard 3 04-29-2005 02:37 PM
PROBLEM: Picture-in-Picture breaks textures?!? vcarlson Vizard 4 10-05-2004 04:22 PM


All times are GMT -7. The time now is 06:09 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC