파이썬[Python]: kivy - SoundLoader 클래스
kivy.core.audio 모듈 - SoundLoader 클래스(class)
/// 설명
사운드 파일을 불러오고 재생합니다.
참고: animation to gesture 모듈 목록
※ 형식
SoundLoader()
reference
https://kivy.org/doc/stable/api-kivy.core.audio.html
참고: animation to gesture 모듈 목록
※ 형식
SoundLoader()
reference
https://kivy.org/doc/stable/api-kivy.core.audio.html
/// 예제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51  | import kivy kivy.require('2.0.0') import os from kivy.app import App from kivy.core.window import Window from kivy.core.audio import SoundLoader from kivy.uix.boxlayout import BoxLayout from kivy.uix.button import Button os.environ['KIVY_AUDIO'] = 'ffpyplayer'  # install ffpyplayer Window.clearcolor = (.6, 1, .8, 1) Window.size = (563, 1001) Window.top, Window.left = 30, 800 class FantasticApp(App):     sound_first = True     def sound_start(self, bt_instance):         if bt_instance.text == 'Play':             bt_instance.text = 'Pause'             if FantasticApp.sound_first == True:                 self.sound = SoundLoader.load('subway.wav')                 FantasticApp.sound_first = False                 if self.sound:                     print("Sound is %.3f seconds" % self.sound.length)                     self.sound.play()             else:                 self.sound.seek(self.pos)                 self.sound.play()         else:             bt_instance.text = 'Play'             self.pos = self.sound.get_pos()             self.sound.stop()         return None     def build(self):         bl = BoxLayout()         bt = Button(text='Play', on_press=self.sound_start)         bl.add_widget(bt)         return bl FantasticApp().run()  | cs | 
/// 출력
/// 사운드 파일
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기