Labels

Tuesday, February 16, 2010

PyGame хөгжим тоглуулах

import pygame

def play_music(music_file):
    """
    mixer.music module-iin tuslamjtaigaar duug streaming hiij
    togluulna ooroor helbel bufferlegdsen ogogdliig togluulj baih zuur
    disknees duunii ogogdliig togluulah bufert hiigeed bna gesen ug    
    """
    clock = pygame.time.Clock()
    try:
        pygame.mixer.music.load(music_file)
        print "%s nertei duu achaalagdlaa!" % music_file
    except pygame.error:
        print "%s gesen duu oldsongui (%s)" % (music_file, pygame.get_error())
        return
    pygame.mixer.music.play()
    while pygame.mixer.music.get_busy():
        # togluulj duussan bol
        clock.tick(30)


# MP3 esvel MIDI formattai duunii file baij bolno
# Programmiin ajillaj baiga folderoos oor gazar 
# duu baigaa bol buren zamiig ni zaaj ogoh heregtei
music_file = "Happy Mariocore.mp3"

# mixeriin tohirgoog hiih
freq = 44100     # audio CD chanartai
bitsize = -16    # unsigned 16 bit
channels = 2     # 1 bol mono, 2 bol stereo
buffer = 2048    # sample-iin too
pygame.mixer.init(freq, bitsize, channels, buffer)

# heviin duunii gemjee 0-ees 1.0-iin hoorond
pygame.mixer.music.set_volume(0.75)

try:
    play_music(music_file)
except KeyboardInterrupt:
    # hereglegch Ctrl/C darval program duusna
    # Zovhon console buyu terminaliin gorimd ajillana
    pygame.mixer.music.fadeout(1000)
    pygame.mixer.music.stop()
    raise SystemExit

No comments: