Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@liripeng/vue-audio-player

Package Overview
Dependencies
Maintainers
0
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liripeng/vue-audio-player

Simple and practical Vue audio player component for PC mobile terminal(简单实用的 PC 移动端的 Vue 音频播放器组件)

  • 2.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Vue Audio Player Component


中文文档 | English Document

Online Demo

Features

  • Vue2 and Vue3 are supported
  • Simple and practical
  • High versatility
  • Support for progress bar dragging
  • Support PC and mobile
  • Support Nuxt SSR
  • Complete documentation and examples

Use

Step one:

npm i -S @liripeng/vue-audio-player

Step two:

// global import
import VueAudioPlayer from '@liripeng/vue-audio-player'

Vue.use(VueAudioPlayer)

or

// part import
import VueAudioPlayer from '@liripeng/vue-audio-player'

components: {
  VueAudioPlayer
}

Step three:

<template>
  <div>
    <div class="name">
      {{ currentAudioName || audioList[0].title }}
    </div>
    <audio-player
      ref="audioPlayer"
      :audio-list="audioList"
      :before-play="handleBeforePlay"
      :show-play-loading="false"
    >
    </audio-player>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentAudioName: '',
      audioList: [
        {
          src: 'http://music.163.com/song/media/outer/url?id=317151.mp3', // Required
          title: 'Audio Title 1', // Optional,Phone lock screen music player display
          artist: 'Artist Name 1', // Optional,Phone lock screen music player display
          album: 'Album Name 1', // Optional,Phone lock screen music player display
          artwork: [
            {
              src: 'https://upload.jianshu.io/users/upload_avatars/1696356/c358e43854eb?imageMogr2/auto-orient/strip|imageView2/1/w/96/h/96/format/webp',
              sizes: '512x512',
              type: 'image/jpg',
            },
          ], // Optional,Phone lock screen music player display
        },
        {
          src: 'http://downsc.chinaz.net/Files/DownLoad/sound1/201906/11582.mp3', // Required
          title: 'Audio Title 2', // Optional,Phone lock screen music player display
        },
      ],
    }
  },

  methods: {
    // Use this function if you want to do something before you start playing
    handleBeforePlay(next) {
      this.currentAudioName =
        this.audioList[this.$refs.audioPlayer.currentPlayIndex].title

      next() // Start play
    },
  },
}
</script>

Prop

PropDescriptionTypeDefault
audio-listAudio playlistArray<Object>-
playback-ratesPlayrate setting listArray<Number>[0.5, 1, 1.5, 2]
show-play-buttonWhether to display the play buttonBooleantrue
show-prev-buttonWhether to display the previous buttonBooleantrue
show-next-buttonWhether to display the next buttonBooleantrue
show-volume-buttonWhether to display the volume buttonBooleantrue
show-progress-barWhether to display a progress barBooleantrue
show-playback-rateWhether to display the play rate buttonBooleantrue
show-play-loadingWhether to display loading on playbackBooleantrue
isLoopWhether the list plays in a loopBooleantrue
disabled-progress-dragDisable progress bar drag functionalityBooleanfalse
disabled-progress-clickDisable progress bar clickable functionalityBooleanfalse
progress-intervalProgress update intervalNumber1000
theme-colorTheme colorString#e35924
before-playThe callback function before the play starts
The play starts after next() is called
(next)=>void-
before-prevPlay the previous callback function
After calling next(), the previous song starts playing
(next)=>void-
before-nextPlay the callback function before the next song
After calling next(), the next song starts playing
(next)=>void-
The rest is consistent with native audio

Event

EventDescriptionCallback
playTriggers when the play starts-
pauseTrigger after play pause-
play-prevTriggers after playing the previous song-
play-nextTriggers after playing the next song-
play-errorTriggered after play error,The parameters are the same as those of the native 'play' methoddata
playingThe play fires every progressInterval second-
timeupdateTriggered when the current play position is sent to changeevent
loadedmetadataThe run script is triggered when the duration of the media element and other media have loaded dataevent
endedTrigger after audio playbackevent
progress-startTrigger before moving the progress barevent
progress-moveTriggered when moving the progress barevent
progress-endTriggered after moving the progress barevent
progress-clickClick the progress bar to triggerevent
The rest is consistent with native audio

Slot

NameDescription
play-prevPlay prev button,The replaceable button icon function remains unchanged
play-startPlay start button,The replaceable button icon function remains unchanged
play-pausePlay pause button,The replaceable button icon function remains unchanged
play-nextPlay next button,The replaceable button icon function remains unchanged

Data

VariableDescriptionDefault
currentPlayIndexThe audio index currently playing0
isPlayingWhether the audio is playingfalse
durationAudio duration''
currentTimeCurrent playback time of audio''
playbackRateCurrent playback rate of audio1

Call with ref,see the components for more data

Method

MethodDescriptionParameters
playStart(opts?: { currentTime: number }) => void
pausePause-
playPrevPrevious-
playNextNext-

Call with ref,see the components for more methods

Update Log

FAQ

Browser compatibility

  • Internet Explorer:not support
  • Firefox:53 and above
  • Chrome:51 and above

Reward the author with milk tea

License

MIT

Last

😘If you think it's helpful, click a 'Star',Any problem found in the process of use can be raised Issue, also very welcome to mention PR.

Keywords

FAQs

Package last updated on 04 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc