Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from Audio to AudioContext to play music #128

Open
17 tasks
martpie opened this issue Aug 3, 2016 · 15 comments
Open
17 tasks

Switch from Audio to AudioContext to play music #128

martpie opened this issue Aug 3, 2016 · 15 comments

Comments

@martpie
Copy link
Owner

martpie commented Aug 3, 2016

last edit: november 30th 2016 (specs added)

The Audio media element works well, but we need the power of AudioContext to add effects, play without interruptions, easy cross fade ect.

That's a huge work.

Tasks

Those are hints on how to accomplish this, these may change depending of our needs. More over, they more explain how "a player work" than "how it should be done"

  • Re-implement the lib/player.js Interface (already existing)
    • play()
    • pause()
    • stop()
    • mute()
    • unmute()
    • setAudioVolume()
    • setAudioPlaybackRate()
    • Unload track and load another one (ex-setAudioSrc())
    • Seek to a certain time (ex-setAudioCurrentTime())
    • + the few utils of player.js
  • Emits corresponding events (may not be needed anymore)
    • play: new track is being played
    • pause: the whole thing is paused
    • ended: the track ended
    • timeupdate: same than HtmlMediaElement
    • error: means what it means

Hints

  • lib/player.js can use Audio tags as they can be used as sources for AudioContext

Help

This issue is required to eventually do #127 #31 #114

@martpie martpie added this to the 0.7 milestone Aug 3, 2016
@martpie martpie changed the title Switch from Audio to AudioContext to play music Player API & switch from Audio to AudioContext to play music Aug 3, 2016
@martpie martpie changed the title Player API & switch from Audio to AudioContext to play music Switch from Audio to AudioContext to play music Aug 3, 2016
@martpie martpie removed this from the 0.7 milestone Aug 9, 2016
@martpie martpie mentioned this issue Sep 21, 2016
18 tasks
@martpie martpie self-assigned this Sep 23, 2016
@YurySolovyov
Copy link
Collaborator

YurySolovyov commented Nov 28, 2016

@KeitIG if we're going to use AudioContext, or OfflineAudioContext, we might want to come up with some kind of custom buffering strategy.

This becomes especially important for ffmpeg, where we can't just wait for the entire file to be converted.

Something like:

  1. Start playing first 20 seconds
  2. On 15 second start buffering next 20 seconds
  3. Swap/Update buffers
  4. On navigation/seeking start over at p.1

@YurySolovyov
Copy link
Collaborator

@YurySolovyov
Copy link
Collaborator

@YurySolovyov
Copy link
Collaborator

@KeitIG how do you expect this to happen? If I'm going to do this, you're expecting the PR with specs and without regressions, right?

@martpie
Copy link
Owner Author

martpie commented Nov 30, 2016

@YurySolovyov I've updated the specs.

"Basically", the things is to rewrite lib/player.js

@martpie
Copy link
Owner Author

martpie commented Nov 30, 2016

A few more things:

  • About the chunkload, this is not required for this issue, we'll see that later if we use ffmpeg
  • I keep myself assignee for now because I want to understand that API, I just have to find enough time, but you can work on this too, we may end up with different implementations of the same thing, that could be interesting to compare our work
  • This is an off-release issue: it's out when it's ready

@YurySolovyov
Copy link
Collaborator

@KeitIG
How about this shipping plan:

  1. Use WebAudio
  2. Use Chunked Loading
  3. Use FFmpeg

Where we can do any number of releases between the steps.
This would allow us test it properly at each step.

@martpie
Copy link
Owner Author

martpie commented Nov 30, 2016

This issue is just about AudioContext, for other things, issues already exist or create another ones.

@martpie
Copy link
Owner Author

martpie commented Dec 1, 2016

Added events specs.

@martpie martpie removed their assignment Dec 9, 2016
@httnn
Copy link

httnn commented Dec 9, 2016

is it really necessary to get rid of HTML5 audio though? it can still be used with the web audio API using createMediaElementSource(): https://developers.google.com/web/updates/2012/02/HTML5-audio-and-the-Web-Audio-API-are-BFFs

it's so much easier to control playback with HTML5 audio than it is with the web audio API. however, if you somehow want to convert and stream tracks from ffmpeg you'd probably have to use web audio API only... unless you first convert the entire audio file temporarily to disk but it gets tricky.

@martpie
Copy link
Owner Author

martpie commented Dec 9, 2016

That's what was planned.

When I say "drop HTML element", I'm speaking about the whole player system, not the things that play/decode music.

This may change in the future though if we decide to use ffmpeg to decode audio, and not <audio>

@YurySolovyov
Copy link
Collaborator

@bodyflex @KeitIG it seems like if we just do the simplest thing possible to replace <audio /> with AudioContext, it won't be all that hard. The question is: what next?

For ffmpeg it would be useful to employ chinked encoding to avoid converting the whole file at once.

For other stuff, I'm not sure what benefit we can get from WebAudio at this point, though I think it is still important.

@martpie
Copy link
Owner Author

martpie commented Dec 9, 2016

I'm not sure what benefit we can get from WebAudio at this point

All the issues depending on this ? (equalizer, crossfade ...)

@OutsourcedGuru
Copy link

For what it's worth, AudioContext.createAnalyser() could be used to create equalizer-like effects as in these examples.

@martpie martpie mentioned this issue Feb 24, 2020
2 tasks
@s0
Copy link

s0 commented Mar 13, 2020

I've effectively implemented this in https://github.com/s0/museeks/blob/synesthesia/src/ui/lib/player.ts, as part of the work towards #31 (see #31 (comment)).

Hopefully I'll soon have a PR open that will address this issue and #31.

s0 added a commit to s0/museeks that referenced this issue Mar 15, 2020
PreciseAudio provides an API for gapless playback, and presents
mostly the same interface as Audio, so switching to this library
didn't require too many changes, and paves the way for martpie#31

PreciseAudio also uses an AudioContext internally,
and makes the audio graph available for mutation via
getAudioNodes(), which will allow for features such as
equalizers (martpie#127) or visualizers / analyzers.

Fixes martpie#128
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants