更新记录

1.0.2(2024-09-28)

修复Android高版本系统调用问题。

1.0.1(2024-08-24)

优化安卓通知栏显示效果。

1.0.0(2024-08-24)

初始化发布

查看更多

平台兼容性

Vue2 Vue3
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.6.8,Android:4.4,iOS:11,HarmonyNext:不确定 × × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×

概述

XF-musicPlayerUTS封装了原生音乐播器,同时支持iOS锁屏界面控制,Android通知栏控制音乐播放等功能。

插件接口

startService

开启音乐播放服务

uni-app项目中(nvue)调用示例:

import { startService } from "@/uni_modules/XF-musicPlayerUTS"

startService({
  musics: [{
        id: 0,
        title: "念人心",
        url: "https://file.tyousan.top/mp3/lianrenxin.mp3",
        singer: "魏心雨",
        album: "https://file.tyousan.top/logo/nanquan@2x.jpg",
        other: "0",
        background: "https://file.tyousan.top/logo/1.jpg",
        fenxiang: 0,
        downmusic: 0,
        pinglun: 0
    }, {
        id: 1,
        title: "二号",
        url: "https://file.tyousan.top/mp3/cemo111.mp3",
        singer: "二号",
        album: "https://file.tyousan.top/logo/kzxd@2x.jpg",
        other: "1",
        background: "https://file.tyousan.top/logo/1.jpg",
        fenxiang: 0,
        downmusic: 0,
        pinglun: 0
    }, {
        id: 2,
        title: "上学歌",
        url: "https://file.tyousan.top/mp3/shangxuege.mp3",
        singer: "上学歌",
        album: "https://file.tyousan.top/logo/1.jpg",
        other: "2",
        background: "https://file.tyousan.top/logo/1.jpg",
        fenxiang: 0,
        downmusic: 0,
        pinglun: 0
    }],
  currentIndex: 0,
  complete: (res) => {
        console.log(res)
  }
});

uni-app x项目(uvue)中调用示例:

import { startService } from "@/uni_modules/XF-musicPlayerUTS";
import { StartOptions,MusicItem } from "@/uni_modules/XF-musicPlayerUTS/utssdk/interface.uts";

let options = {
  musics: [{
        id: 0,
        title: "念人心",
        url: "https://file.tyousan.top/mp3/lianrenxin.mp3",
        singer: "魏心雨",
        album: "https://file.tyousan.top/logo/nanquan@2x.jpg",
        other: "0",
        background: "https://file.tyousan.top/logo/1.jpg",
        fenxiang: 0,
        downmusic: 0,
        pinglun: 0
    }, {
            id: 1,
            title: "二号",
            url: "https://file.tyousan.top/mp3/cemo111.mp3",
            singer: "二号",
            album: "https://file.tyousan.top/logo/kzxd@2x.jpg",
            other: "1",
            background: "https://file.tyousan.top/logo/1.jpg",
            fenxiang: 0,
            downmusic: 0,
            pinglun: 0
        }, {
            id: 2,
            title: "上学歌",
            url: "https://file.tyousan.top/mp3/shangxuege.mp3",
            singer: "上学歌",
            album: "https://file.tyousan.top/logo/1.jpg",
            other: "2",
            background: "https://file.tyousan.top/logo/1.jpg",
            fenxiang: 0,
            downmusic: 0,
            pinglun: 0
        }] as MusicItem[],
    currentIndex: 0,
  complete: (res : any) => {
    console.log(res)
  }
} as StartOptions;
startService(options);

可用性

iOS、Android系统

可提供的1.0.0及更高版本

stopService

停止音乐播放服务

uni-app项目中(nvue)调用示例:

import { stopService } from "@/uni_modules/XF-musicPlayerUTS"

stopService({
  complete: (res) => {
        console.log(res)
  }
});

uni-app x项目(uvue)中调用示例:

import { stopService } from "@/uni_modules/XF-musicPlayerUTS";
import { StopOptions } from "@/uni_modules/XF-musicPlayerUTS/utssdk/interface.uts";

let options = {
  complete: (res : any) => {
    console.log(res)
  }
} as StopOptions;
stopService(options);

可用性

Android系统

可提供的1.0.0及更高版本

addEventListener

播放器状态监听

uni-app项目中(nvue)调用示例:

import { addEventListener } from "@/uni_modules/XF-musicPlayerUTS"

addEventListener({
  complete: (res) => {
        console.log(res)
  }
});

uni-app x项目(uvue)中调用示例:

import { addEventListener } from "@/uni_modules/XF-musicPlayerUTS";
import { AddEventOptions } from "@/uni_modules/XF-musicPlayerUTS/utssdk/interface.uts";

let options = {
  complete: (res : any) => {
    console.log(res)
  }
} as AddEventOptions;
addEventListener(options);

可用性

Android系统

可提供的1.0.0及更高版本

removeEventListener

移除播放器状态监听

uni-app项目中(nvue)调用示例:

import { removeEventListener } from "@/uni_modules/XF-musicPlayerUTS"

removeEventListener({
  complete: (res) => {
        console.log(res)
  }
});

uni-app x项目(uvue)中调用示例:

import { removeEventListener } from "@/uni_modules/XF-musicPlayerUTS";
import { RemoveOptions } from "@/uni_modules/XF-musicPlayerUTS/utssdk/interface.uts";

let options = {
  complete: (res : any) => {
    console.log(res)
  }
} as RemoveOptions;
removeEventListener(options);

可用性

Android系统

可提供的1.0.0及更高版本

addMusicData

添加音乐数据

uni-app项目中(nvue)调用示例:

import { addMusicData } from "@/uni_modules/XF-musicPlayerUTS"

addMusicData({
  musics: [{
        id: 0,
        title: "念人心",
        url: "https://file.tyousan.top/mp3/lianrenxin.mp3",
        singer: "魏心雨",
        album: "https://file.tyousan.top/logo/nanquan@2x.jpg",
        other: "0",
        background: "https://file.tyousan.top/logo/1.jpg",
        fenxiang: 0,
        downmusic: 0,
        pinglun: 0
    }, {
        id: 1,
        title: "二号",
        url: "https://file.tyousan.top/mp3/cemo111.mp3",
        singer: "二号",
        album: "https://file.tyousan.top/logo/kzxd@2x.jpg",
        other: "1",
        background: "https://file.tyousan.top/logo/1.jpg",
        fenxiang: 0,
        downmusic: 0,
        pinglun: 0
    }, {
        id: 2,
        title: "上学歌",
        url: "https://file.tyousan.top/mp3/shangxuege.mp3",
        singer: "上学歌",
        album: "https://file.tyousan.top/logo/1.jpg",
        other: "2",
        background: "https://file.tyousan.top/logo/1.jpg",
        fenxiang: 0,
        downmusic: 0,
        pinglun: 0
    }],
  complete: (res) => {
        console.log(res)
  }
});

uni-app x项目(uvue)中调用示例:

import { addMusicData } from "@/uni_modules/XF-musicPlayerUTS";
import { MusicDataOptions,MusicItem } from "@/uni_modules/XF-musicPlayerUTS/utssdk/interface.uts";

let options = {
  musics: [{
        id: 0,
        title: "念人心",
        url: "https://file.tyousan.top/mp3/lianrenxin.mp3",
        singer: "魏心雨",
        album: "https://file.tyousan.top/logo/nanquan@2x.jpg",
        other: "0",
        background: "https://file.tyousan.top/logo/1.jpg",
        fenxiang: 0,
        downmusic: 0,
        pinglun: 0
    }, {
            id: 1,
            title: "二号",
            url: "https://file.tyousan.top/mp3/cemo111.mp3",
            singer: "二号",
            album: "https://file.tyousan.top/logo/kzxd@2x.jpg",
            other: "1",
            background: "https://file.tyousan.top/logo/1.jpg",
            fenxiang: 0,
            downmusic: 0,
            pinglun: 0
        }, {
            id: 2,
            title: "上学歌",
            url: "https://file.tyousan.top/mp3/shangxuege.mp3",
            singer: "上学歌",
            album: "https://file.tyousan.top/logo/1.jpg",
            other: "2",
            background: "https://file.tyousan.top/logo/1.jpg",
            fenxiang: 0,
            downmusic: 0,
            pinglun: 0
        }] as MusicItem[],
  complete: (res : any) => {
    console.log(res)
  }
} as MusicDataOptions;
addMusicData(options);

可用性

iOS、Android系统

可提供的1.0.0及更高版本

selectMusicItem

指定播放音乐

uni-app项目中(nvue)调用示例:

import { selectMusicItem } from "@/uni_modules/XF-musicPlayerUTS"

selectMusicItem({
  index: 1,
  complete: (res) => {
        console.log(res)
  }
});

uni-app x项目(uvue)中调用示例:

import { selectMusicItem } from "@/uni_modules/XF-musicPlayerUTS";
import { MusicItemOptions } from "@/uni_modules/XF-musicPlayerUTS/utssdk/interface.uts";

let options = {
  index: 1,
  complete: (res : any) => {
    console.log(res)
  }
} as MusicItemOptions;
selectMusicItem(options);

可用性

iOS、Android系统

可提供的1.0.0及更高版本

getCurrentMusic

获取正在播放的音频信息

uni-app项目中(nvue)调用示例:

import { getCurrentMusic } from "@/uni_modules/XF-musicPlayerUTS"

selectMusicItem({
  complete: (res) => {
        console.log(res)
  }
});

uni-app x项目(uvue)中调用示例:

import { getCurrentMusic } from "@/uni_modules/XF-musicPlayerUTS";
import { GetMusicOptions } from "@/uni_modules/XF-musicPlayerUTS/utssdk/interface.uts";

let options = {
  index: 1,
  complete: (res : any) => {
    console.log(res)
  }
} as GetMusicOptions;
getCurrentMusic(options);

可用性

iOS、Android系统

可提供的1.0.0及更高版本

getDuration

获取音频总进度

uni-app项目中(nvue)调用示例:

import { getDuration } from "@/uni_modules/XF-musicPlayerUTS"

let res = getDuration();
console.log(res)

uni-app x项目(uvue)中调用示例:

import { getDuration } from "@/uni_modules/XF-musicPlayerUTS";

let res = getDuration();
console.log(res)

可用性

iOS、Android系统

可提供的1.0.0及更高版本

getCurrentPosition

获取已经播放进度

uni-app项目中(nvue)调用示例:

import { getCurrentPosition } from "@/uni_modules/XF-musicPlayerUTS"

let res = getCurrentPosition();
console.log(res)

uni-app x项目(uvue)中调用示例:

import { getCurrentPosition } from "@/uni_modules/XF-musicPlayerUTS";

let res = getCurrentPosition();
console.log(res)

可用性

iOS、Android系统

可提供的1.0.0及更高版本

isPlaying

是否正在播放音频

uni-app项目中(nvue)调用示例:

import { isPlaying } from "@/uni_modules/XF-musicPlayerUTS"

let res = isPlaying();
console.log(res)

uni-app x项目(uvue)中调用示例:

import { isPlaying } from "@/uni_modules/XF-musicPlayerUTS";

let res = isPlaying();
console.log(res)

可用性

iOS、Android系统

可提供的1.0.0及更高版本

playerMode

切换播放模式

uni-app项目中(nvue)调用示例:

import { playerMode } from "@/uni_modules/XF-musicPlayerUTS"

let res = playerMode();
console.log(res)

uni-app x项目(uvue)中调用示例:

import { playerMode } from "@/uni_modules/XF-musicPlayerUTS";

let res = playerMode();
console.log(res)

可用性

iOS、Android系统

可提供的1.0.0及更高版本

playerPre

播放上一条

uni-app项目中(nvue)调用示例:

import { playerPre } from "@/uni_modules/XF-musicPlayerUTS"

let res = playerPre();
console.log(res)

uni-app x项目(uvue)中调用示例:

import { playerPre } from "@/uni_modules/XF-musicPlayerUTS";

let res = playerPre();
console.log(res)

可用性

iOS、Android系统

可提供的1.0.0及更高版本

playerPlay

暂停后播放

uni-app项目中(nvue)调用示例:

import { playerPlay } from "@/uni_modules/XF-musicPlayerUTS"

let res = playerPlay();
console.log(res)

uni-app x项目(uvue)中调用示例:

import { playerPlay } from "@/uni_modules/XF-musicPlayerUTS";

let res = playerPlay();
console.log(res)

可用性

iOS、Android系统

可提供的1.0.0及更高版本

playerPause

暂停播放

uni-app项目中(nvue)调用示例:

import { playerPause } from "@/uni_modules/XF-musicPlayerUTS"

let res = playerPause();
console.log(res)

uni-app x项目(uvue)中调用示例:

import { playerPause } from "@/uni_modules/XF-musicPlayerUTS";

let res = playerPause();
console.log(res)

可用性

iOS、Android系统

可提供的1.0.0及更高版本

playerNext

暂停下一条

uni-app项目中(nvue)调用示例:

import { playerNext } from "@/uni_modules/XF-musicPlayerUTS"

let res = playerNext();
console.log(res)

uni-app x项目(uvue)中调用示例:

import { playerPause } from "@/uni_modules/XF-musicPlayerUTS";

let res = playerNext();
console.log(res)

可用性

iOS、Android系统

可提供的1.0.0及更高版本

playerRandom

随机播放

uni-app项目中(nvue)调用示例:

import { playerRandom } from "@/uni_modules/XF-musicPlayerUTS"

let res = playerRandom();
console.log(res)

uni-app x项目(uvue)中调用示例:

import { playerRandom } from "@/uni_modules/XF-musicPlayerUTS";

let res = playerRandom();
console.log(res)

可用性

iOS、Android系统

可提供的1.0.0及更高版本

playerSeek

设置播放进度

uni-app项目中(nvue)调用示例:

import { playerSeek } from "@/uni_modules/XF-musicPlayerUTS"

let res = playerSeek(112000);
console.log(res)

uni-app x项目(uvue)中调用示例:

import { playerSeek } from "@/uni_modules/XF-musicPlayerUTS";

let res = playerSeek(112000);
console.log(res)

可用性

iOS、Android系统

可提供的1.0.0及更高版本

playerSpeed

设置倍速值(0.5-2.0)

uni-app项目中(nvue)调用示例:

import { playerSpeed } from "@/uni_modules/XF-musicPlayerUTS"

let res = playerSpeed(1.5);
console.log(res)

uni-app x项目(uvue)中调用示例:

import { playerSpeed } from "@/uni_modules/XF-musicPlayerUTS";

let res = playerSpeed(1.5);
console.log(res)

可用性

iOS、Android系统

可提供的1.0.0及更高版本

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问