Last active
August 26, 2020 13:22
-
-
Save natcl/0b9ff4b422cfb42ccdac to your computer and use it in GitHub Desktop.
Simple Kivy audio player
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <MySlider@Slider>: | |
| canvas: | |
| Clear | |
| Color: | |
| rgb: (0.2, 0.2, 0.2) | |
| Rectangle: | |
| pos: self.pos | |
| size: self.width, self.height | |
| Color: | |
| rgb: (1, 0, 0) | |
| Rectangle: | |
| pos: self.pos | |
| size: self.width * (self.value_normalized if self.orientation == 'horizontal' else 1), self.height * (self.value_normalized if self.orientation == 'vertical' else 1) | |
| <MyLayout@BoxLayout>: | |
| padding: 5, 5 | |
| spacing: 5 | |
| size_hint: .75, .75 | |
| Button: | |
| text: "Play" | |
| on_press: app.buttonCallback() | |
| size_hint: .60, 1 | |
| MySlider: | |
| id: volume_slider | |
| step: 1 | |
| on_value: app.sliderCallback(self.value) | |
| orientation: 'vertical' | |
| size_hint: .20, 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| from kivy.app import App | |
| from kivy.uix.boxlayout import BoxLayout | |
| from kivy.clock import Clock | |
| import os, subprocess | |
| class MyLayout(BoxLayout): | |
| pass | |
| class Audio_Player(App): | |
| def getAlsaVolume(self, *largs): | |
| volume_string = subprocess.check_output(['amixer', '-c', '1', 'get', 'Digital'])[172:177] | |
| self.volume = self.parseInt(volume_string) | |
| self.root.ids.volume_slider.value = self.volume | |
| def sliderCallback(self, value): | |
| os.system('amixer --quiet -c 1 set Digital {0}%'.format(value)) | |
| print value | |
| def buttonCallback(self): | |
| os.system('killall mplayer') | |
| self.process = subprocess.Popen('mplayer -nolirc -ao alsa:device=hw=1,0 "{0}"'.format('/home/pi/Music/08 - Strawberry Fields Forever (2009 Digital Remaster).m4a'), shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) | |
| print 'button' | |
| self.getAlsaVolume() | |
| def parseInt(self, string): | |
| return int(''.join([x for x in string if x.isdigit()])) | |
| def build(self): | |
| self.root = MyLayout() | |
| Clock.schedule_interval(self.getAlsaVolume, 1) | |
| return self.root | |
| if __name__ == '__main__': | |
| Audio_Player().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have got a WinError in 14th string. Explain pls how does it works? And the 24th, 19