lua制作flash钢琴

效果预览

apk使用manaluax打包,源码在文末提供。

应用体验下载地址:https://www.magicalapk.com/appview?id=1705213059764

源码

  • 布局代码

{
   LinearLayout;
   gravity="center";
   layout_height="fill";
   orientation="vertical";
   layout_width="fill";
   {
      LinearLayout;
      layout_weight="120";
      layout_width="match_parent";
      {
         ScrollView;
         layout_width="match_parent";
         layout_height="match_parent";
         {
            TextView;
            textIsSelectable=true;
            layout_height="match_parent";
            id="opern";
            layout_width="match_parent";
         };
      };
   };
   {
      LinearLayout;
      layout_weight="1";
      layout_width="match_parent";
      orientation="vertical";
      {
         LinearLayout;
         orientation="horizontal";
         layout_width="match_parent";
         {
            Button;
            backgroundColor="#FFFFFF";
            id="A";
            singleLine="true";
            layout_weight="1";
            text="A";
            textColor="#000000";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="B";
            singleLine="true";
            layout_weight="1";
            text="B";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="C";
            singleLine="true";
            layout_weight="1";
            text="C";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="D";
            singleLine="true";
            layout_weight="1";
            text="D";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="E";
            singleLine="true";
            layout_weight="1";
            text="E";
            layout_margin="10px";
         };
      };
      {
         LinearLayout;
         orientation="horizontal";
         layout_width="match_parent";
         {
            Button;
            backgroundColor="#000000";
            id="F";
            singleLine="true";
            layout_weight="1";
            text="F";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="G";
            singleLine="true";
            layout_weight="1";
            text="G";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="H";
            singleLine="true";
            layout_weight="1";
            text="H";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="I";
            singleLine="true";
            layout_weight="1";
            text="I";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="J";
            singleLine="true";
            layout_weight="1";
            text="J";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
      };
      {
         LinearLayout;
         orientation="horizontal";
         layout_width="match_parent";
         {
            Button;
            backgroundColor="#FFFFFF";
            id="K";
            singleLine="true";
            layout_weight="1";
            text="K";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="L";
            singleLine="true";
            layout_weight="1";
            text="L";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="M";
            singleLine="true";
            layout_weight="1";
            text="M";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="N";
            singleLine="true";
            layout_weight="1";
            text="N";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="O";
            singleLine="true";
            layout_weight="1";
            text="O";
            layout_margin="10px";
         };
      };
      {
         LinearLayout;
         layout_width="match_parent";
         {
            Button;
            backgroundColor="#000000";
            id="P";
            singleLine="true";
            layout_weight="1";
            text="P";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="Q";
            singleLine="true";
            layout_weight="1";
            text="Q";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="RKey";
            singleLine="true";
            layout_weight="1";
            text="R";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="S";
            singleLine="true";
            layout_weight="1";
            text="S";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="T";
            singleLine="true";
            layout_weight="1";
            text="T";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
      };
      {
         LinearLayout;
         layout_width="match_parent";
         {
            Button;
            backgroundColor="#FFFFFF";
            id="U";
            singleLine="true";
            layout_weight="1";
            text="U";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="V";
            singleLine="true";
            layout_weight="1";
            text="V";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="W";
            singleLine="true";
            layout_weight="1";
            text="W";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="X";
            singleLine="true";
            layout_weight="1";
            text="X";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="Y";
            singleLine="true";
            layout_weight="1";
            text="Y";
            layout_margin="10px";
         };
      };
      {
         LinearLayout;
         layout_width="match_parent";
         {
            Button;
            backgroundColor="#000000";
            id="opernOn";
            singleLine="true";
            layout_weight="1";
            text="曲谱开";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="opernOff";
            singleLine="true";
            layout_weight="1";
            text="曲谱关";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="Z";
            singleLine="true";
            layout_weight="1";
            text="Z";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#FFFFFF";
            id="more";
            singleLine="true";
            layout_weight="1";
            text="更多";
            layout_margin="10px";
         };
         {
            Button;
            backgroundColor="#000000";
            id="contact";
            singleLine="true";
            layout_weight="1";
            text="作者QQ";
            textColor="#FFFFFF";
            layout_margin="10px";
         };
      };
   };
};
  • 核心代码
require "import"

import "manalua"

import "layout.main"

import "android.net.Uri"

import "android.content.Intent*"



activity.setContentView(loadlayout(main))



function openfile(path)

   return io.open(path):read("*a")

end



--打开曲谱

opernOn.onClick=function()

   local path=activity.getLuaDir().."/res/lyrics/lyric.txt"

   local txt=openfile(path)

   opern.setText(txt)

end



-- 关闭曲谱

opernOff.onClick=function()

   opern.setText("")

end



-- 播放琴音

function playMusic(letter)

   filepath=activity.getLuaDir().."/res/sound/piano"..tostring(string.byte(letter)-64)..".mp3"

   import "android.media.MediaPlayer"

   mediaPlayer = MediaPlayer()

   --初始化参数

   mediaPlayer.reset()

   --设置播放资源

   mediaPlayer.setDataSource(filepath)

   --开始缓冲资源

   mediaPlayer.prepare()

   --缓冲完成的监听

   mediaPlayer.setOnPreparedListener(MediaPlayer.OnPreparedListener{

      onPrepared=function(mediaPlayer)

         mediaPlayer.start()

      end

   })



   --播放完成回调

   mediaPlayer.setOnCompletionListener(MediaPlayer.OnCompletionListener{

      onCompletion=function(mediaPlayer)

         mediaPlayer.release()

      end

   })

end




local btntbl={A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,RKey,S,T,U,V,W,X,Y,Z}

-- 循环设置监听事件

for i=65,90 do

   local btn=btntbl[i-64]

   btn.onClick=function()

      playMusic(string.char(i))

   end

end




function str2tbl(str)

   local chartbl={}

   for i=1,#str do

      local char=string.sub(str,i,i)

      table.insert(chartbl,char)

   end

   return chartbl

end




contact.onClick=function()

   url="mqqwpa://im/chat?chat_type=wpa&uin=512357657"

   activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))

end



more.onClick=function()

   url="https://s.pdb2.com/l/doalEcC5IPc3f9qf"

   viewIntent = Intent("android.intent.action.VIEW",Uri.parse(url))

   activity.startActivity(viewIntent)

end

源码下载

  • 下载源码,放到manaluax的project目录下解压即可使用。
  • 下载地址:下载:https://wwp.lanzoul.com/i6xbo1rga47g  密码:3bjo
  • 如需manaluax开发工具,在公众号发送消息【manaluax】即可获得。

    本文由【产品经理不是经理】gzh 同步发布,欢迎关注

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/458282.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

蓝桥杯--冶炼金属

目录 一、题目 二、解决代码 (1)版本一(报错:超时) 代码分析 (2)版本二(不会超时) 代码分析 (3)版本三(最终精简版)…

【数据分析】数据分析介绍

专栏文章索引:【数据分析】专栏文章索引 目录 一、介绍 二、生活中的数据分析 1.无处不在的数据 2.为什么要进行数据分析? 三、数据挖掘案例 1.案例分析 一、介绍 数据采集:数据采集是指从不同来源收集原始数据的过程,包括…

孙宇晨最新研判:加密货币将成为全球金融基础设施的一部分

近日,波场TRON创始人、火币HTX全球顾问委员会委员孙宇晨接受了在加密社区有重要影响力的媒体平台Bankless的专访,就自己的从业经历、涉足加密行业的理想、波场TRON本身的发展和未来的市场走向等话题进行了详细的分享。 孙宇晨认为,波场TRON的使命是为那些没有银行账户的人提供…

Ubuntu——以桌面应用为主的Linux发行版操作系统

目录 一、Ubuntu简介 二、Ubuntu下载及安装 1.Swap分区的作用 2.语言环境 3.软件管理——apt 3.1配置文件 3.2软件源配置文件格式 3.3DPKG常用命令 三、常用命令总结 1. date——显示或设定系统的日期和与时间 2.cal——显示日历 3.设置时区 4.修改密码——passwd…

学习使用js获取当前ip地址的方法,使用第三方API获取ip地址

学习使用js获取当前ip地址的方法,使用第三方API获取ip地址 使用 DNS 查询使用第三方 API 使用 DNS 查询 DNS 是一种用于解析主机名为 IP 地址的系统。可以使用 JavaScript DNS 查询来获取本机IP地址。下面是如何使用 JavaScript 进行DNS查询的示例代码。 <p class"loc…

【数学】【计算几何】1453. 圆形靶内的最大飞镖数量

作者推荐 视频算法专题 本文涉及知识点 数学 计算几何 LeetCoce:1453. 圆形靶内的最大飞镖数量 Alice 向一面非常大的墙上掷出 n 支飞镖。给你一个数组 darts &#xff0c;其中 darts[i] [xi, yi] 表示 Alice 掷出的第 i 支飞镖落在墙上的位置。 Bob 知道墙上所有 n 支飞…

CASIA-HWDB手写体数据集gnt生成为png格式

👑一、数据集获取 1.1 官方链接获取gnt文件 http://www.nlpr.ia.ac.cn/databases/download/feature_data/HWDB1.1trn_gnt.ziphttp://www.nlpr.ia.ac.cn/databases/download/feature_data/HWDB1.1tst_gnt.zip 1.2 百度网盘获取gnt文件 链接:https://pan.baidu.com/s/1pKa…

上位机图像处理和嵌入式模块部署(qmacvisual条件判断)

【 声明&#xff1a;版权所有&#xff0c;欢迎转载&#xff0c;请勿用于商业用途。 联系信箱&#xff1a;feixiaoxing 163.com】 之前我们在qmacvisual里面先创建项目&#xff0c;然后继续创建流程&#xff0c;这其实是一种顺序流程。更普遍的情况是&#xff0c;客户希望有些条…

Windows安装Kibana之保姆级教程

Kibana 安装 介绍&#xff1a;一款开源的数据分析和可视化平台&#xff0c;可对Elasticsearch 索引中的数据进行搜索、查看、交互操作&#xff1b;可理解为 Elasticsearch 的web管理后台 下载&#xff1a;点击https://www.elastic.co/cn/downloads/past-releases#kibana-->…

同城便民小程序源码系统 带完整的安装代码包以及搭建教程

同城便民小程序源码系统的开发&#xff0c;源于对市民生活需求的深入洞察。在日常生活中&#xff0c;人们经常需要查询各类便民信息&#xff0c;如房屋出租、二手交易、家政服务等。然而&#xff0c;传统的信息发布方式往往存在信息分散、查找困难等问题。因此&#xff0c;开发…

C# 线性搜索算法

线性搜索被定义为一种顺序搜索算法&#xff0c;从一端开始&#xff0c;遍历列表中的每个元素&#xff0c;直到找到所需的元素&#xff0c;否则搜索将继续&#xff0c;直到数据集的末尾。 线性搜索算法 线性搜索算法如何工作&#xff1f; 在线性搜索算法中&#xff1a; …

数字信封

一、概念 数字信封是将对称密钥通过非对称加密&#xff08;即&#xff1a;有公钥和私钥两个&#xff09;的结果分发对称密钥的方法。数字信封是实现信息保密性验证的技术。 二、过程描述 在数字信封中&#xff0c;信息发送方采用对称密钥来加密信息内容&#xff0c;然后将此…

YOLOv1预测阶段后处理----Non-maximum suppression(NMS非极大值抑制)

前言&#xff1a;预了解 NMS&#xff0c;去掉冗余的框。在目标检测中&#xff0c;不论是最初的region proposal&#xff0c;还是后来的anchor box&#xff0c;不可避免的一个问题就是对于同一个物体&#xff0c;会预测出多个bounding box&#xff0c;如下左图所示。而NMS所做的…

Java 使用 EasyExcel 实现导入导出(新手篇教程)

官网镇楼↓&#xff0c;觉得我写的不好的同学可以去官网看哦 EasyExcel Maven <dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>3.3.3</version> </dependency> Excel 导入 示例&…

6、Design Script之列表

Range 在DesignScript中,Range是从起点到终点的一系列数字,使用指定的步距(间距类型),并有以下的初始化方法: start..end..step; start..end..#amount; start..end..~approximate; Range可以是数字的,也可以是字母的。 字母范围因大小写而异。 开始,结束. .#数量范围(…

【软考高项】六、信息技术发展之计算机网络知识点

1、网络作用划分 个人局域网(PAN)、局域网(LAN)、城域网(MAN)、广域网(WAN)、公用网、专用网。 2、OSI七层 物理层、数据链路层、网络层、传输层、会话层、表示层、应用层 3、广域网协议类型 PPP点对点协议、ISDN综合业务数字网、xDSL(DSL数字用户线路的统称:HDSL.SDSL、M…

遗嘱消息(Will Message)介绍与示例 _ MQTT 5.0 特性详解

什么是 MQTT 遗嘱消息&#xff1f; 在现实世界中&#xff0c;一个人可以制定一份遗嘱&#xff0c;声明在他去世后应该如何分配他的财产以及应该采取什么行动。在他去世后&#xff0c;遗嘱执行人会将这份遗嘱公开&#xff0c;并执行遗嘱中的指示。 在 MQTT 中&#xff0c;客户端…

比较不错超声波清洗机有哪些?2024年口碑一绝超声波清洗机推荐

2024年&#xff0c;随着科技的不断进步和消费者需求的日益增长&#xff0c;超声波清洗机在生活中的应用变得越来越广泛。无论是珠宝首饰、眼镜、电子产品还是医疗器械&#xff0c;高效、快速、安全的清洗方式正成为人们追求的目标。超声波清洗机以其独特的清洗方式和卓越的清洗…

让数据在业务间高效流转,镜舟科技与NineData完成产品兼容互认

近日&#xff0c;镜舟科技与NineData完成产品兼容测试。在经过联合测试后&#xff0c;镜舟科技旗下产品与NineData云原生智能数据管理平台完全兼容&#xff0c;整体运行高效稳定。 镜舟科技致力于帮助中国企业构建卓越的数据分析系统&#xff0c;打造独具竞争力的“数据护城河”…
最新文章