Giter VIP home page Giter VIP logo

eeui-plugin-audio's Introduction

音频播放

安装

eeui plugin install https://github.com/aipaw/eeui-plugin-audio

卸载

eeui plugin uninstall https://github.com/aipaw/eeui-plugin-audio

引用

const audio = app.requireModule("eeui/audio");

播放音频

/**
 * @param url    音频地址
 */
audio.play(url)

暂停播放

audio.pause()

停止播放

audio.stop()

指定进度

/**
 * @param millisecond    毫秒数
 */
audio.seek(millisecond)

是否播放

/**
 * @return boolean  true|false
 */
let variable = audio.isPlay()

调整音量

/**
 * @param vol    (0-100)
 */
audio.volume(vol)

循环播放

/**
 * 设置音频是否循环播放
 * @param loop    true|false
 */
audio.loop(loop)

播放回调

/**
 * 监听音频播放状态
 * @param callback  回调事件,result:{url:音频地址, current:已播放毫秒数, duration:总时长毫秒数,percent:播放百分比进度}
 */
audio.setCallback(callback(result))

获取时长

/**
 * 通过音频地址获取视频时长
 * @param url       视频地址
 * @param callback  回调事件,result:{url:音频地址,duration:总时长毫秒数}
 */
audio.getDuration(url, callback(result))

示例代码

<template>
    <div style="align-items: center;justify-content: center">

        <text class="res">{{res}}</text>
        <text class="button" @click="play">播放</text>
        <text class="button" @click="pause">暂停</text>
        <text class="button" @click="stop">停止</text>
        <text class="button" @click="seek">指定进度</text>
        <text class="button" @click="loop">{{isloop?'取消循环':'循环'}}</text>
        <text class="button" @click="duration">获取时长</text>

    </div>
</template>
<script>
    const navigationBar = app.requireModule('navigationBar');
    const audio = app.requireModule('audio');

    export default{
        data(){
            return {
                res: '',
                url: 'https://eeui.app/assets/samples/audio.mp3',
                isloop: false
            }
        },
        mounted(){
          navigationBar.setTitle("音频播放");
          audio.setCallback((res) => {
            this.res = res;
          });
        },
        methods: {
            play(){
                audio.play(this.url)
            },
            pause(){
                audio.pause()
            },
            stop(){
                audio.stop()
            },
            seek(){
                audio.seek(20000)
            },
            loop(){
                this.isloop = !this.isloop;
                audio.loop(this.isloop)
            },
            duration(){
                audio.getDuration(this.url, (res) => {
                    this.res = res;
                });
            }
        },
    }
</script>
<style scoped>
  .res {
    color: #000000;
    font-size: 24px;
  }
  .button {
    width: 230px;
    height: 80px;
    line-height: 80px;
    margin-top: 24px;
    text-align:center;
    color: #ffffff;
    background-color:#3EB4FF;
    font-size: 26px;
  }
</style>

eeui-plugin-audio's People

Contributors

aipaw avatar

Stargazers

 avatar  avatar

Watchers

 avatar

eeui-plugin-audio's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.