示例#1
0
 def get_random_song(self):
     if self.song_playlist is None:
         m_dir = resfile('audio/music')
         song_playlist = [os.path.join(m_dir,f) for f in os.listdir(m_dir)]
         random.shuffle(song_playlist)
         self.song_playlist = iter(song_playlist)
     return self.song_playlist.next()
示例#2
0
    def init_music(self):
        self.m_media = Phonon.MediaObject(self)
        self.m_output = audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self)
        Phonon.createPath(self.m_media, audioOutput)
        self.song_playlist = None
        self.m_media.aboutToFinish.connect(self.play_next_song)
        self.play_next_song()
        self.play_pause_music_action = play_pause_music_action = QAction(u"Music", self)
        play_pause_music_action.setCheckable(True)
        play_pause_music_action.toggled.connect(self.play_pause_music)
        self.view_menu.addAction(play_pause_music_action)
        play_pause_music_action.setChecked(True)
        
        self.s_media = Phonon.MediaObject(self)
        self.s_output = audioOutput = Phonon.AudioOutput(Phonon.GameCategory, self)
        Phonon.createPath(self.s_media, audioOutput)
        self.__sound_sources = {}
        for soundname, soundfile in SOUNDS.items():
            self.__sound_sources[soundname] = Phonon.MediaSource(\
                resfile('audio/sound/'+ soundfile))

        self.sound_action = sound_action = QAction(u"Sound", self)
        sound_action.setCheckable(True)
        sound_action.toggled.connect(self.mute)
        self.__last_s_volume = self.s_output.volume()
        sound_action.setChecked(True)
        self.view_menu.addAction(sound_action)