Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to seek with AudioContext

I would like to create buttons that will play next/prev song on click, but they should seek the music on long press.

I did manage to change songs, but I couldn't find the seek methods. Also how to make it play from beginning?

And is there a way to determine how much have passed since the beginning of the song? I found that buffer have duration, but no sing of actual play time.

At init:

context = new (window.AudioContext || window.webkitAudioContext)()

To play song:

var buffer = song.buffer
var source = context.createBufferSource()
source.buffer = song.buffer
source.connect(analysers.main)
source.start(0, offset || 0)
like image 836
Akxe Avatar asked Dec 22 '15 11:12

Akxe


People also ask

What is AudioContext destination?

destination. The destination property of the BaseAudioContext interface returns an AudioDestinationNode representing the final destination of all audio in the context. It often represents an actual audio-rendering device such as your device's speakers.

How many AudioContext are there?

How many Audio Contexts should I have? A: Generally, you should include one AudioContext per page, and a single audio context can support many nodes connected to it. Though you may include multiple AudioContexts on a single page, this can lead to a performance hit.

What is window AudioContext?

The AudioContext interface represents an audio-processing graph built from audio modules linked together, each represented by an AudioNode . An audio context controls both the creation of the nodes it contains and the execution of the audio processing, or decoding.


1 Answers

Guess, you should use AudioBufferNode (it has ability to do seek) - https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/start

Also, this wrapper might be usefull - https://github.com/eipark/buffaudio

like image 109
Dmitry Volokh Avatar answered Oct 16 '22 08:10

Dmitry Volokh