kivy制作安卓APP--简单音乐播放器

简述

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()

项目链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

智能视界探索者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值