hithis is my first script in blender and
python. the idea is to play songs in the
specified directory . it has pause play and
replay feature.
if you don’t want to waste hours if time on typing then paste this.
next post has the link
hithis is my first script in blender and
python. the idea is to play songs in the
specified directory . it has pause play and
replay feature.
if you don’t want to waste hours if time on typing then paste this.
next post has the link
http://www.filehosting.org/file/details/489768/playList.py
you may hav to use your email id to download
so what do you think about it…
i request you to re-upload it in your comments.
because ithe plan i used to upload deletes the file in 28 days
can’t you just copy and paste the .py file using the code tags:
like this
hi,
i know that but when i copy auch a long text and paste it my phone hangs
so what do you think about it.
is it a good start?
should buy a new phone
hi how many of you downloaded this
################
#HAPPY BLENDING#
################
##########################################
# #
# Author : Yashwanth.C.B (C.B.Y) #
# #
# Name : Simple Play List #
# #
# Location : India #
# #
# Date : 5:21PM 5/30/2015 #
# #
##########################################
#Hi BA users
#This is my first script in blender and even in python
#
#feel free to add features.. like seek()
#
#Are you feeling lazy to add a custom sound track and a script to control it for your game. This is a light weight way to do it.
#
#This playlist script is suitable for racing games. the idea is to play music files in a folder one after another with some basic manipulation features
#
#I hope it is bug free
#
#And if anyone wants to use this script in their game, please don't delete the author name ;) and also feel free to give me a credit in your game <3
#
import bge
import aud
import os
#Change This Path To Your Wish
#The double slash at the last of the string is must
################################################################
playListPath = "E:\Blender Works\BlenderWorks\car game\songs\\"#
################################################################
################################
#Controls:
# N to Pause\ Resume
# M to Play Next
# , to Restart Current
#
#Setup the logic bricks Accordingly.
#
#In True pulse mode (Freq=60) and Tap
#
################################
controller = bge.logic.getCurrentController( )
owner = controller.owner
pauseKey = controller.sensors['pauseKey']
playKey = controller.sensors[ 'playKey']
restartKey = controller.sensors['restartKey']
loop = controller.sensors['loop'] #This is a delay sensor(true pulse freq =180, Delay = 180). you can set it to what ever you wish. this is used to loop the sound
owner['device'] = aud.device()
def getPlayList( path):
playList = []
playList = os.listdir( path)
return filterSounds( playList)
def filterSounds( playList):
#The folder may contain album art files which aren't sounds actually. So that is why I added this Function
#is there any straight-forward way to do this
for file in playList:
#add .wav or .ogg to your wish
if not getExtension( file) == 'mp3':
playList.remove( file)
return playList
def getExtension( fileName):
length = len( fileName)
tempList = fileName.split( '.')
extension = tempList.pop( len ( tempList) -1)
return extension
def playSong():
#Hope you are familiar with aud.*
if playKey.positive:
if not 'play' in owner:
owner['play'] = True
owner['factory'] = aud.Factory(nextSong(True))
owner['handle'] = owner['device'].play(owner['factory'], False)
else:
owner['handle'].stop()
owner['factory'] = aud.Factory(nextSong(True))
owner['handle'] = owner['device'].play(owner['factory'], False)
elif restartKey.positive:
owner['handle'].stop()
owner['factory'] = aud.Factory(nextSong(False))
owner['handle'] = owner['device'].play(owner['factory'], False)
elif pauseKey.positive:
if 'play' in owner and not 'pause' in owner:
owner['handle'].pause()
owner['pause'] = True
elif owner['pause'] == True:
owner['handle'].resume()
del owner['pause']
elif loop.positive:
if not 'handle' in owner or owner['handle'].status == False:
owner['play'] = True
owner['factory'] = aud.Factory(nextSong(True))
owner['handle'] = owner['device'].play(owner['factory'], False)
def nextSong(next):
#if next is True it returns the next song else it returns the current song(suitable for restarting the music
playList = getPlayList(playListPath)
absPlayList = []
for s in playList:
absPlayList.append(playListPath + s)
if not 'number' in owner:
owner['number'] = 0
return absPlayList[owner['number']]
else:
if not next == True:
return absPlayList[owner['number']]
else:
if owner ['number'] < owner['songsCount']:
owner ['number'] = owner ['number'] + 1
print(owner ['number'])
return absPlayList[owner ['number']]
else:
owner['number'] = 0
return absPlayList[owner['number']]
def Main():
if not 'songsCount' in owner:
owner['songsCount'] = (len(getPlayList(playListPath)) -1 )
print(owner['songsCount'])
playSong()
Main()
#########
#THE END#
#########
Its not working
Yashwanth, it’s not your fault, it’s because BGE is horrible for coding. Your code looks really bad. To work it requires:
Some of this days I’ll do a bge guide: “How to properly make games in bge without raising a spaghetti monster.”
Once my friend said this to me on some code I did and I didn’t code for months. Never, ever say this shit to anyone. Say something like this: “Your code needs work.” or something like that.
It wasn’t my intention to disparage him or anything. I said that it wasn’t his fault, and it isn’t. If this were in any other engine, I’m sure his code would look a lot better. I coded a lot of horrible monsters in the past, one can’t get depressed for that. I still code some monster now and then tough. There’s always room for improving.
Yeah. People react different. I’m just saying that the wording can be better. No problem with hard precise critique but to say that it’s bad is not fun to hear.
You did at least say what he should do and guided him to be a better coder. It was just that one sentence that can really get to you.
Hey guys, its me with different account as I lost the password. thank you for the advice. now I am using unreal engine and blender
I missed this place. and the vacation that made the time to open account back in those days