示例#1
0
def show_details(play_song):  # show details
    global filename_path

    filelabel['text'] = 'Playing' + ' - ' + os.path.basename(play_song)
    file_data = os.path.splitext(play_song)
    #print(filename_path)
    #print(file_data)
    if file_data[1] == '.mp3':
        audio = MP3(play_song)
        totallength = audio.info.length
        #print(totallength)
    else:
        a = mixer.sound(play_song)  #use sound for wav file provided by mixer
        # FOR wav file , not for mp3
        totallength = a.get_length()  # this include pause time also ERROR

    mins, secs = divmod(totallength,
                        60)  # storing quotient in mins and remainder in secs
    print(round(mins))
    print(round(secs))
    #time_format = '{:2d}:{:2d}'.format(mins, secs)  #02d: show 0(optional) +2 digits + d:int
    #print(time_format)
    lengthlabel['text'] = 'Total Length' + ' - ' + str(
        round(mins)) + ':' + str(round(secs))

    t1 = threading.Thread(target=time_counter, args=(totallength, ))
    t1.start()
示例#2
0
def generateRandom():
    randomLat = random.uniform(42, 44)
    randomLon = random.uniform(-78, -80)
    newDistance = calculate.distanceToDuff(radians(randomLat),
                                           radians(randomLon))

    if newDistance < initialDistance:
        print("WARMER")
    elif newDistance > initialDistance:
        sound = mixer.Sound("really.wav")
        sound.play()
        sleep(5)
    else:
        sound = mixer.sound("really.wav")
        sound.play()
示例#3
0
def show_details(play_song):
    filedata = os.path.splitext(play_song)
    if (filedata[1]) == '.mp3':
        audio = MP3(play_song)
        total_length = audio.info.length

    else:
        a = mixer.sound(play_song)
        total_length = a.get_length()

    min, sec = divmod(total_length,
                      60)  #div- total_length/60, mod- total_length%60
    min = round(min)
    sec = round(sec)
    timeformat = '{:02d}:{:02d}'.format(min, sec)
    lengthLabel['text'] = "Total length- " + timeformat
    t1 = threading.Thread(target=start_count, args=(total_length, ))
    t1.start()
示例#4
0
def show_details(play_song):
    file_data=os.path.splitext(play_song)
    if file_data[1]=='.mp3':
        audio=MP3(play_song)
        total_length=audio.info.length
    else:
        a=mixer.sound(play_song)
        total_length=a.get_length()

    #div- total_length/60, mod-total_length%60
    mins,secs= divmod(total_length,60)  
    mins=round(mins)
    secs=round(secs)
    timef='[:02d]:[:02d]'.format(mins,secs)
    lengthlabel['text']="Total length"+'-'+timef
    
    t1=threading.Thread(target=start_count,args=(total_length,))
    t1.start()
示例#5
0
文件: main.py 项目: vikas2e03/Musicca
def show_details(play_song):
    file_data = os.path.splitext(play_song)
    print(file_data)

    if file_data[1] == '.mp3':
        audio = MP3(play_song)
        total_length = audio.info.length

    else:
        a = mixer.sound(play_song)
        total_length = a.get_length()

    mins, secs = divmod(total_length, 60)
    mins = round(mins)
    secs = round(secs)
    timeformat = "{:02d}:{:02d}".format(mins, secs)
    lengthLabel["text"] = "total_length" + "  " + timeformat
    t1 = threading.Thread(target=start_count, args=(total_length, ))
    t1.start()
def show_details(play_song):
    #filelabel['text'] = "Playing" + ' :: ' + os.path.basename(filename_path)
    file_data = os.path.splitext(play_song)

    if file_data[1] == '.mp3':
        audio = MP3(play_song)
        total_length = audio.info.length
    else:
        a = mixer.sound(play_song)
        total_length = a.get_length()

    #   DIV = total length/60, mod = total length % 60
    mins, secs = divmod(total_length,60)
    mins = round(mins)
    secs = round(secs)
    timeformat = '{:02d}:{:02d}'.format(mins, secs)
    lengthlabel['text'] = "Total Length" + ' :: ' + timeformat

    t1 = threading.Thread(target=start_count, args=(total_length,))
    t1.start()
示例#7
0
def show_details(play_song):
    filelabel['text'] = 'Playing' + '-' + os.path.basename(filename_path)

    file_details = os.path.splitext(play_song)

    if file_details[1] == '.mp3':
        audio = MP3(play_song)
        total_duration = audio.info.length

    else:
        a = mixer.sound(play_song)
        total_duration = a.get_length()

    mins, secs = divmod(total_duration, 60)
    mins = round(mins)
    secs = round(secs)
    timeformat = '{:02d}:{:02d}'.format(mins, secs)
    lengthlabel['text'] = 'Total Duration' + '-' + timeformat

    t1 = threading.Thread(target=start_count, args=(total_duration, ))
    t1.start()
示例#8
0
def on_key(event):
    #detect any normal key press (0..9, A..Z, a..z)
    if event.char == event.keysym:
        if event.char == '1':
            #play the sound instance
            d1.play()
        if event.char == '2':
            d2.play()


prompt = "Press key 1 or 2 to play a sound"

#initialize the pygame mixer
mixer.init(44100)

#pick sounds you have...
#copy to working directory or indicate full path
try:
    #create the sound instances
    d1 = mixer.sound("rain-01.mp3")
    d2 = mixer.sound("audiocheck.net_whitenoise.mp3")
except:
    prompt = "Error: Sound file not found"

root = Tk.Tk()
label1 = Label(root, text=prompt, width=len(prompt), be='yellow', fg='red')
label1.pack()
label1.bind_all('<Key>', on_key)

root.mainloop()
示例#9
0
                game = False
                pygame.quit()
                quit()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    playery_change = -8
                if event.key == pygame.K_DOWN:
                    playery_change = +8
                if event.key == pygame.K_SPACE:
                    if fire_state == "ready":
                        bullet_sound = mixer.sound('laser.wav')
                        bullet_sound.play()
                        firey = playery
                        fire_fire(firex, firey)

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
                    playery_change = 0

        playery += playery_change

        if playery <= 100:
            playery = 100
        elif playery >= 450:
            playery = 450
示例#10
0
# I could not import sound from pymixer
# I will spend a little more time on it a little later

from gpiozero import Button
import pygame.mixer
from pygame.mixer import sound
from signal import pause

pygame.mixer.init()

button_sounds = {
    Button(2): sound("samples/drum_tom_mid_hard.wav"),
    Button(27): sound("samples/drum/cymbal_open.wav")
}

for button, sound in button_sounds.item():
    button.when_pressed = sound.play

pause()