npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sygnas/simple-audio-player

v1.0.1

Published

Play and stop only audio player.

Downloads

3

Readme

syg-simple-audio-player

Play and stop only audio player. 再生と停止だけのオーディオプレイヤー。

Description

試聴ボタンなどで使う。 「再生だけできて、アクティブ状態を持たせられればいい」というだけのオーディオプレイヤー。

ストリーミング、非ストリーミング両対応。

Install

npm install --save @sygnas/simple-audio-player

Usage

HTML

<!-- 非ストリーミング -->
<button class="js-audio btn-audio" data-audio-src="foo.mp3" data-audio-type="file">Sound 1</button>
<button class="js-audio btn-audio" data-audio-src="bar.mp3" data-audio-type="file">Sound 2</button>

<!--
ストリーミング
HDS/HLS/MSE形式のストリーミングを自動判別する
下記のファイルが存在する想定。
HDS形式:http://stm.foo.bar/abcd1234.mp4/manifest.f4m
HLS形式:http://stm.foo.bar/abcd1234.mp4/playlist.m3u8
MSE形式:http://stm.foo.bar/abcd1234.mp4/manifest.mpd
-->
<button class="js-audio btn-audio" data-audio-src="stm.foo.bar/abcd1234.mp4">ストリーミング</button>

<!-- 停止ボタン -->
<p><button class="js-audio-stop">停止</button></p>

CSS

.btn-audio[data-audio-status = "play"]{
  background-color: #b8860b;
}
.btn-audio[data-audio-status = "pause"]{
  background-color: #73d8ff;
}

Javascript

import AudioPlayer from '@sygnas/simple-audio-player';

// .js-audio をクリックすると data-audio-src属性で指定された音声データを再生する
const audio_player = new AudioPlayer('.js-audio');

// 停止ボタン
document.querySelector('.js-audio-stop')
  .addEventListener('click', () => {
    audio_player.stop();
  });

Attributes

再生する音声データのURL、音声データタイプ、ステータスなどをボタンの data属性に格納している。

data-audio-src

再生する音声データのURL。 ストリーミングの場合はURLの一部を指定する。

例:http://stm.foo.bar/abcd1234.mp4/manifest.f4mstm.foo.bar/abcd1234.mp4

data-audio-type

音声データのタイプを指定する。

| 値 | 備考 | | ---- | --- | | file | 非ストリーミングの場合は必ず記入 | | hls | HLS形式 | | hds | HDS形式 | | mse | MSE形式 | | 無指定 | HLS / HDS / MSE を自動選択する |

data-audio-status

再生・一時停止などの状態が格納される。

| 値 | 備考 | | ---- | --- | | play | 再生中 | | pause | 一時停止 | | stop | 停止 | | 属性が存在しない | 停止。デフォルト状態 |

<!-- foo.mp3 を再生しているので、 data-audio-status="play" になっている -->
<button data-audio-src="foo.mp3" data-audio-type="file" data-audio-status="play">foo</button>

<!-- http://stm.foo.bar/abcd1234.mp4/manifest.f4m をストリーミング再生 -->
<!-- ストリーミング形式は自動選択したいので data-audio-type は無指定 -->
<button data-audio-src="stm.foo.bar/abcd1234.mp4">ストリーミング</button>

Options

const audio_player = new AudioPlayer('.js-audio', {config});

デフォルト設定

const defaults = {
  attr_src: 'data-audio-src',
  attr_status: 'data-audio-status',
  attr_type: 'data-audio-type',
  // 以下、syg-audio-src の設定
  hds: {
    protcol: 'http://',
    playlist: '/manifest.f4m',
  },
  hls: {
    protcol: 'http://',
    playlist: '/playlist.m3u8',
  },
  mse: {
    protcol: 'http://',
    playlist: '/manifest.mpd',
    autoplay: false,
  },
};

| パラメータ | デフォルト | 備考 | | ---- | ---- | ---- | | attr_src | 'data-audio-src' | オーディオソースを指定する属性の名前 | | attr_status | 'data-audio-status' | 状態を格納する属性の名前 | | attr_type | 'data-audio-type' | ソースのタイプを指定する属性の名前 | | hds / hls / mse | | syg-audio-src のパラメータを参照 |

Property

is_playing {Boolean}

再生中なら true

now_playing_btn {HTMLElement}

現在再生中のエレメント。

targets {NodeList}

対象のエレメント

audio_src {syg-audio-src}

ストリーミングに対応したHTML5 Audioソース管理。

Methods

stop()

現在再生している音声を停止する。 audio.currentTime = 0; をしている。

License

MIT