简述
python kivy库制作的安卓简单音乐播放器,是一个简单小demo,本来用来年会节目控制音乐流程的,分享出来给大家参考,自带kivy launch将该文件解压到根目录,安装里面的launch apk就可以运行。
具体如何使用与安装kivy自行百度。
界面
源码
# -*-coding:utf-8-*-
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.audio import SoundLoader,Sound
from kivy.lang import Builder
Builder.load_string('''
<MenuPage>:
BoxLayout:
orientation:'vertical'
Button:
text:'Yi_Jian_Mei'
on_press:root.plays()
Button:
text:'Shi_Nian'
on_press:root.plays2()
Button:
text:'Shi_Nian_Gao_Chao'
on_press:root.plays3()
Button:
text:'Shi_Nian_Xu_Jie'
on_press:root.plays4()
Button:
text:'Shao_Nian'
on_press:root.plays5()
''')
class MenuPage(Screen):
M = SoundLoader.load('1.mp3') #一剪梅
M2 = SoundLoader.load('2.mp3') #十年
M3 = SoundLoader.load('3.mp3') #演员唱十年
M4 = SoundLoader.load('4.mp3') #唱错词后接着的十年
M5 = SoundLoader.load('5.mp3') #少年
def plays(self):
if MenuPage.M.state == 'stop':
MenuPage.M4.stop()
MenuPage.M2.stop()
MenuPage.M5.stop()
MenuPage.M3.stop()
MenuPage.M.play()
else:
MenuPage.M.stop()
def plays2(self):
if MenuPage.M2.state == 'stop':
MenuPage.M.stop()
MenuPage.M4.stop()
MenuPage.M3.stop()
MenuPage.M5.stop()
MenuPage.M2.play()
else:
MenuPage.M2.stop()
def plays3(self):
if MenuPage.M3.state == 'stop':
MenuPage.M.stop()
MenuPage.M4.stop()
MenuPage.M2.stop()
MenuPage.M5.stop()
MenuPage.M3.play()
else:
MenuPage.M3.stop()
def plays4(self):
if MenuPage.M4.state == 'stop':
MenuPage.M.stop()
MenuPage.M3.stop()
MenuPage.M2.stop()
MenuPage.M5.stop()
MenuPage.M4.play()
else:
MenuPage.M4.stop()
def plays5(self):
if MenuPage.M5.state == 'stop':
MenuPage.M.stop()
MenuPage.M3.stop()
MenuPage.M4.stop()
MenuPage.M2.stop()
MenuPage.M5.play()
else:
MenuPage.M5.stop()
sm = ScreenManager()
menu = MenuPage(name='menu')
sm.add_widget(menu)
class TestApp(App):
def build(self):
return sm
if __name__ in ('__main__', '__android__'):
TestApp().run()