Movatterモバイル変換


[0]ホーム

URL:


Lifecycle: stableCodecov test coverageR-CMD-check

{howler} - Interactive AudioPlayer

{howler} is a package that utilises thehowler.js library toplay audio on the modern web.

Installation

This package is available on CRAN and r-universe. To install thelatest version:

install.packages("devtools")devtools::install_github("ashbaldry/howler")

Usage

The HTML way to include an audio file in any shiny application/webpage is to use the<audio> tag. This can generallyonly handle one audio file, and cannot (easily) be manipulated from theserver side.

tags$audio(src ="audio/sound.mp3",type ="audio/mp3",autoplay =NA,controls =NA)

howler.js uses theWeb Audio API, andwith this we are able to create an audio player that can solve both ofthe above issues and more:

library(shiny)library(howler)ui<-fluidPage(title ="howler Example",howler(elementId ="sound",tracks =list("Track 1"="audio/track_1.mp3","Track 2"="audio/track_2.mp3"),auto_continue =TRUE,auto_loop =TRUE,seek_ping_rate =1000  ),howlerPreviousButton("sound"),howlerPlayPauseButton("sound"),howlerNextButton("sound"))server<-function(input, output, session) {observe({req(input$sound_seek)if (round(input$sound_seek)==10) {pauseHowl("sound")    }elseif (round(input$sound_seek)==20) {changeTrack("sound","Track 2")    }  })}shinyApp(ui, server)

Module

The{howler} package also includes a lightweight modulehowlerModuleUI andhowlerModuleServer thatadds a bit of styling to replicate the style of a standard<audio> HTML player.

Howler module UI

Examples

All examples are available in theExamplesdirectory and can be run locally by installing the{howler}package:


[8]ページ先頭

©2009-2025 Movatter.jp