播放器雏形

This commit is contained in:
@fawn-nine
2023-08-11 14:54:03 +08:00
parent 72d35bae31
commit 57d70c40f2
768 changed files with 15285 additions and 65 deletions

View File

@@ -0,0 +1,124 @@
## 介绍
本插件是android原生插件仅支持Android app版本的 uni-app 项目使用。
本插件适配 android 5.0 以上minSdkVersion 21
本插件的使用方法在插件包里的 musicNotification.vue 有详细使用说明
## 方法:
- init( Object ); 初始化通知栏
- update(Object); 更新通知栏信息
- playOrPause(Boolean); 切换播放状态
- openLockActivity(Boolean); 切换锁屏状态
- cancel(); 移除通知栏
- favour(Boolean);切换收藏状态
- openPermissionSetting() 打开通知栏权限页面
- ~~initSongs(Funcion )~~ getLocalSong(Funcion ) 获取本地音乐
- setWidgetStyle(Object) 设置桌面小部件风格 **2.0.6 新增**
- createNotification( Funcion ) 创建通知栏 **3.0.1 新增**
- switchNotification(Boolean) 是否使用系统通知栏模板 **3.0.3 新增**
- checkOverlayDisplayPermission() 判断是否有悬浮窗权限 **3.0.6 新增**
- showFloatWindow (String) 显示桌面歌词浮窗 **3.0.6 新增**
- hideFloatWindow(); 关闭桌面歌词浮窗**3.0.6 新增**
- setPosition(number); 设置播放进度,单位毫秒**3.1.4 新增**
##### plus.globalEvent.addEventListener 添加监听
##### plus.globalEvent.removeEventListener 取消监听
| 类型 | 说明 |
| -------------------------- | ------------------------------ |
| musicNotificationPause | 播放按钮事件回调 |
| musicNotificationPrevious | 上一首按钮事件回调 |
| musicNotificationNext | 下一首按钮事件回调 |
| musicNotificationFavourite | 收藏按钮事件回调 |
| musicMediaButton | 耳机事件回调**3.0.4 新增)** |
| musicLifecycle | 生命周期事件回调 |
| musicNotificationClose | 关闭按钮事件回调**3.1.5 新增)** |
例:
```javascript
// 添加监听
plus.globalEvent.addEventListener('musicNotificationPause', function(e) {
//初始化回调
});
// 添加移除
plus.globalEvent.removeEventListener('musicNotificationPause')
```
##### 隐藏搜藏按钮:
请打开 manifest.json -> 原生插件配置 -> XZH-musicNotification -> favour 内填写**`true开启`**或者**`false`**(关闭),不支持动态改变
## 注意:
1. 开启锁屏页, 因为各个手机品牌对该功能的限制不同,所以要根据自己的需求调整。比喻小米手机,需要用户手动开启”开启锁屏显示“、”后台弹出界面“这两个权限才可以。
2. 关于自定义 icon复制新的图片覆盖 插件文件夹 res 里面的所有 drawable 开头的文件里面的对应图片就行了,不过我个人建议除了 music_icon.png 图片其他而已不要动最好,因为可能有分辨率适配问题。
3. 监听耳机事件回调,注意只能在应用播放音乐的时候才能接收到事件,如果有的耳机按键按了没反应,不要怀疑是插件问题,插件已经把事件直接返回了,没有事件,那就是耳机根本没发起事件。
4. 离线打包集成:
在 dcloud_uniplugins.json 进入下面代码
```json
{
"plugins": [{
"type": "module",
"name": "XZH-musicNotification",
"class": "com.xzh.musicnotification.MusicNotificationModule"
}]
}
```
在 AndroidManifest.xml 进入下面代码
```xml
<application>
.......
<meta-data
android:name="xzh_favour"
android:value="true"/>
<meta-data
android:name="xzh_theme_color"
android:value="#55000000"/>
<meta-data
android:name="xzh_title_color"
android:value="#ffffff"/>
<meta-data
android:name="xzh_artist_color"
android:value="#ffffff"/>
</application>
```
## 关于原生插件使用方法
[官方文档](https://uniapp.dcloud.io/api/extend/native-plugin)

View File

@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#8F8F8F"
android:alpha="0.8">
<group android:scaleX="1.7142857"
android:scaleY="1.7142857"
android:translateX="-8.571428"
android:translateY="-8.571428">
<path
android:fillColor="@android:color/white"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</group>
</vector>

View File

@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#8F8F8F"
android:alpha="0.8">
<group android:scaleX="0.85714287"
android:scaleY="0.85714287"
android:translateX="1.7142857"
android:translateY="1.2857143">
<path
android:fillColor="@android:color/white"
android:pathData="M16.5,3c-1.74,0 -3.41,0.81 -4.5,2.09C10.91,3.81 9.24,3 7.5,3 4.42,3 2,5.42 2,8.5c0,3.78 3.4,6.86 8.55,11.54L12,21.35l1.45,-1.32C18.6,15.36 22,12.28 22,8.5 22,5.42 19.58,3 16.5,3zM12.1,18.55l-0.1,0.1 -0.1,-0.1C7.14,14.24 4,11.39 4,8.5 4,6.5 5.5,5 7.5,5c1.54,0 3.04,0.99 3.57,2.36h1.87C13.46,5.99 14.96,5 16.5,5c2,0 3.5,1.5 3.5,3.5 0,2.89 -3.14,5.74 -7.9,10.05z"/>
</group>
</vector>

View File

@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#FD2C12"
android:alpha="0.8">
<group android:scaleX="0.85714287"
android:scaleY="0.85714287"
android:translateX="1.7142857"
android:translateY="1.2857143">
<path
android:fillColor="@android:color/white"
android:pathData="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z"/>
</group>
</vector>

View File

@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#8F8F8F"
android:alpha="0.8">
<group android:scaleX="1.4285715"
android:scaleY="1.4285715"
android:translateX="-5.142857"
android:translateY="-5.142857">
<path
android:fillColor="@android:color/white"
android:pathData="M6,18l8.5,-6L6,6v12zM16,6v12h2V6h-2z"/>
</group>
</vector>

View File

@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#8F8F8F"
android:alpha="0.8">
<group android:scaleX="1.2"
android:scaleY="1.2"
android:translateX="-2.4"
android:translateY="-2.4">
<path
android:fillColor="@android:color/white"
android:pathData="M9,16h2L11,8L9,8v8zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM13,16h2L15,8h-2v8z"/>
</group>
</vector>

View File

@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#8F8F8F"
android:alpha="0.8">
<group android:scaleX="1.2"
android:scaleY="1.2"
android:translateX="-2.4"
android:translateY="-2.4">
<path
android:fillColor="@android:color/white"
android:pathData="M10,16.5l6,-4.5 -6,-4.5v9zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</group>
</vector>

View File

@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#8F8F8F"
android:alpha="0.8">
<group android:scaleX="1.4285715"
android:scaleY="1.4285715"
android:translateX="-5.142857"
android:translateY="-5.142857">
<path
android:fillColor="@android:color/white"
android:pathData="M6,6h2v12L6,18zM9.5,12l8.5,6L18,6z"/>
</group>
</vector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 498 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 413 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 702 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -0,0 +1,47 @@
{
"name": "XZH-musicNotification",
"id": "XZH-musicNotification",
"version": "3.1.7",
"description": "Android音乐通知栏",
"_dp_type": "nativeplugin",
"_dp_nativeplugin": {
"android": {
"plugins": [{
"type": "module",
"name": "XZH-musicNotification",
"class": "com.xzh.musicnotification.MusicNotificationModule"
}],
"integrateType": "aar",
"compileOptions": {
"sourceCompatibility": "1.8",
"targetCompatibility": "1.8"
},
"dependencies": [
"androidx.core:core-ktx:1.8.0",
"androidx.media:media:1.6.0",
"androidx.appcompat:appcompat:1.1.0",
"org.jetbrains.kotlin:kotlin-reflect:1.8.0"
],
"minSdkVersion": "21",
"useAndroidX": true,
"parameters": {
"favour": {
"des": "是否开启收藏按钮",
"key": "xzh_favour"
},
"themeColor": {
"des": "widget背景色(请使用 ARGB 格式)",
"key": "xzh_theme_color"
},
"titleColor": {
"des": "widget歌名字体色(请使用 ARGB 格式)",
"key": "xzh_title_color"
},
"artistColor": {
"des": "widget歌手字体色(请使用 ARGB 格式)",
"key": "xzh_artist_color"
}
}
}
}
}