@ethanol/ionic-react-hooks
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

@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

/@ethanol/ionic-react-hooks/

    Package Sidebar

    Install

    npm i @ethanol/ionic-react-hooks

    Weekly Downloads

    9

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    62 kB

    Total Files

    10

    Last publish

    Collaborators

    • ethanol