1.0.6 • Published 3 years ago

@ethanol/ionic-react-hooks v1.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

@ethanol/ionic-react-hooks

Ionic react hooks by Ethan Olsen

This library is not still being developed and is not to be used in applications till done.

NPM JavaScript Style Guide

Install

npm install --save @ethanol/ionic-react-hooks

Usage

useAudioPlayer

import React from 'react'

import { useAudioPlayer } from '@ethanol/ionic-react-hooks'

interface Props {
  audioUrl: string
}

export const AudioComponent = ({ audioUrl }: Props) => {
  // ---- hooks ----
  // > refs
  const progressRef = useRef<HTMLInputElement>(null!)

  // > player
  const {
    curTime,
    duration,
    isLoading,
    isPaused,
    seekTo,
    skip,
    togglePlayPause
  } = useAudioPlayer({
    audioUrl: audioUrl,
    progressRef: progressRef
  })

  return (
    <div>
      {/* Display current time and duration */}
      <p>
        {curTime}/{duration}
      </p>
      {/* Progress slider */}
      <input
        type='range'
        ref={progressRef}
        onChange={(e) => seekTo(parseInt(e?.target?.value ?? curTime))}
      />
      {/* Play pause */}
      <button onClick={togglePlayPause}>{isPaused ? 'Play' : 'Pause'}</button>
      {/* Skip 15 seconds forward and backwards */}
      <button onClick={() => skip(15)}>Skip +15</button>
      <button onClick={() => skip(-15)}>Skip -15</button>
    </div>
  )
}

License

MIT © o2dependent

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago