Giter Site home page Giter Site logo

dascritch / cpu-audio Goto Github PK

View Code? Open in Web Editor NEW
24.0 3.0 2.0 4.31 MB

An audio WebComponent to provide timecoded links and other features to an audio tag

Home Page: https://dascritch.github.io/cpu-audio/

License: GNU Lesser General Public License v3.0

HTML 20.20% CSS 4.82% JavaScript 72.06% Shell 2.40% SCSS 0.52%
webcomponents audio-player hyperlink vanilla playlist sound timecoded-links

cpu-audio's Introduction

CPU-Audio WebComponent

An audio WebComponent to provide an user-interface, timecoded links and some other features to an <audio> tag.

Purpose

A generic WebComponent crafted with a hashtag observer for <audio> tags with fancy interface, hyperlinks, chaptering, playlist and share buttons.

When you load a page :

  1. if your URL has a hash with a timecode (https://example.com/page#tagID&t=10m), the service will position the named <audio controls> at this timecode (here, #TagID at 10 minutes) ;
  2. or, if a audio source (qualified by its url) was played in your website, and was unexpectedly exited, the service will reposition its <audio controls> at the same timecode.

During the page life :

  • if an <audio controls> anchor is linked with a timecode, as <a href="#sound&t=10m">, the service will play this tag at this timecode ;
  • no cacophony : when a <audio controls> starts, it will stop any other <audio controls> in the page ;
  • if you have a <cpu-controller> in your page, it will clone the playing <cpu-audio> interface.

This link starts the upper player at 20:45, and a link can limit playing between a start (0:05) and end (0:08) marks

Features

TL;DR ? See it in action

  • hyperlink <audio> tags to a specific time, using not well-known Media Fragment standards ;
  • standards first, future-proof ;
  • only one single file to deploy ;
  • pure vanilla, no dependencies to any framework, so usable in any JS framework ;
  • progressive enhancement, can works even without proper WebComponent support ;
  • add an UI, customizable via attributes and CSS variables ;
  • exists in different graphic themes ;
  • responsive liquid design ;
  • recall the player where it was unexpectedly left (click on a link when playing) ;
  • play only one sound in the page ;
  • playlist with auto-advance ;
  • play only a range between 2 timestamps ;
  • chapters, using standards WebVTT ;
  • alternate navigation for a finest precision on smartphones ;
  • global <cpu-controller> .

It could have been done via polyfills or frameworks, but I wanted a plain standard, vanilla javascript, easy to install and configure.

HOW TO install

A unique and lightweight js file to install, without any dependencies.

Keyboard functions

When the interface got the focus, you can use those keys :

  • Space : play/pause audio
  • Enter : play/pause audio (only on play/pause button)
  • : -5 seconds
  • : +5 seconds
  • : back to start
  • End : to the end, finish playing, ev. skip to the sound in playlist
  • Escape : back to start, stop playing
  • and : move focus between entries in panels (Enter to select)

For handheld users, a long press on the timeline will show you another interface for a more precise navigation (Desktop users can try it via a right click on it).

Some links

Participate

Credits

Thank you to my lovely friends :

Really sorry, NerOcrO

Keeping in touch

cpu-audio's People

Contributors

dascritch avatar nerocro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cpu-audio's Issues

Support MSE API or DASH for non-bufferred playing

from dascritch/ondemiroir-audio-tag#22

May help issues when switching rapidly position at low bandwith.

Well, not useful. As the #39 bug is mainly a configuration or a protocol missing.
See also http://blog.eleven-labs.com/fr/video-live-dash-hls/

Show only a playing instance of cpu-audio

Suppose :

  • on a page, you have
    • a <cpu-controller>
    • numerous <cpu-audio>, in a playlist

We may want to show only the active <cpu-audio>, hiding the others <cpu-audio>.

May be it is a wrong idea, maybe using css vars is enough.

canonical attribute must accept hash

A very stupid issue in element_cpu.js, function update_time is building the canonical URL with the CURRENT id element. This is not critical, but really a stupid idea. I should have wrote that in a rush.

    update_time(event) {
        let timecode = convert.SecondsInTime(this.audiotag.currentTime);
        let link_to = absolutize_url(this.audiotag.dataset.canonical)+'#';
        // WHAAAT ? I should have done something wrong there
        link_to += this.audiotag.id ? (this.audiotag.id+'&') : '';
        link_to += 't='+timecode;

The best idea is to look if a valid ID is already in URL's hash, out of other parameters

Clean html : use <progress> for timeline

Instead of ugly <div> with a percent width...

Notes : <input type="range"> is too heavy to customize, and nor Chrome, Safari, Firefox can differ the track before the thumb. there is somewhere a way with ::before and attr(value) , but I can't find it anymore

Playing time range using start-point,end-point notation

dascritch/ondemiroir-audio-tag#25

cf https://www.w3.org/2008/WebVideo/Fragments/WD-media-fragments-spec/#smpte-time

t=10,20   # => results in the time interval [10,20)
t=,20     # => results in the time interval [0,20)
t=10      # => results in the time interval [10,end)

Needs to

  • improve hash url parser
  • put event on timecode to stop player, or using progress
  • stops player even in no WebComponent browsers
  • remove it on changing position, out of end position
  • adding visual element

Use a playlist for continuous playing at a page

from dascritch/ondemiroir-audio-tag#47

if an <cpu-audio playlist="name"> finishes, search in the same page for next <cpu-audio playlist="name"> (even without controls ?) and start playing

  • define the attribute finally
  • make a API to add in playlist
  • expose playlist in document.CPU API
  • playlists in a page, play next audio in playlist parametrable via API
  • make event at end to move next in playlist
  • add to stacked audio timecode for end
  • change container to use named playlists
  • show playlist in <cpu-controller>

Create a live configurator page

  • form for html source
  • form for css variables
  • support reset event for CSS edition
  • a dummy "button" event switches pan
  • include in .MD
  • separate style modifications events
  • group widths on width breakpoints
  • show only changed css parameters

Use QUnit v2

Alas, my conversion failed with "global failures : no tests were run" ????
It seems a regular problem with QUnit v2.

Prepare design and key bindings for RTL localizations

Arabic, Hebraic and others RTL (Right To Left) languages are usually using right-to-left timelines. A lot of abstraction work is to do there :

  • check RTL support for native players
  • reverse button groups
  • reverse chapters list
  • reverse timeline
  • reverse key bidings (the most difficult ?)

Need a CPU.is_playing_audiotag()

To check if a audiotag element is the same one playing, we sometimes compare their ID, sometime using isEqualNode() . There is a lot of confusion and is not really DRY.

examples :

(self.audiotag.id === CPU_Audio.current_audiotag_playing.id) 

or

audiotag.isEqualNode(CPU_Audio.current_audiotag_playing)

We need a utility method on the global API, to simplify the code.

In playlist, next song must restart at 0

In a playlist context, if the next sound piece was already started and not pointing at 0:00, ending its predecessor will continue the play, instead to restart it at its begin.

querySelector_apply too largely called

The third parameter of querySelector_apply(selector, callback, subtree) is facultative. When it is not defined, it will query on the whole document tree.

But it MAY BE a very wrong idea o some places :

cpu_controller.class.js, connectedCallback() :

querySelector_apply('.canonical', element_prevent_link_on_same_page);

should be limited to the shadowDOM only

Preview position when hovering an internal link

On a host page, when hovering/focus a link that goes to a moment of a player, show the target link on the timeline of the targeted player.

  • will need a special API on cpu-audio element :
    • highlight_moment
    • highlight_hide
    • highlight_range
    • highlight_chapter
  • add a event on host page on hovering/focus <a href="">
    • check it links on the same page
    • check it links to a cpu-audio
    • prepare to highlight_hide when pointer goes out or focus out
  • add a event on webcomponent on hovering/focus <a href=""> (for chapter list)
  • also hightlight on <cpu-controller>

May be linked to #40

Better way to change time position on mobile

When I'm a mobile user
I want to have a more precise way to position on the timeline
Because i'm not very precise with my finger on a 2 hours long timeline

The user have actually 2 ways to reposition the player at a certain timeline, out of hyperlinks :

  • With the keyboard and , which (obviously) doesn't exists on handheld
  • By touching the timeline, but it is really imprecise.

Why not make appears a special selector, as

<input type="time" min="0" max="1:1:1" step="1" /> 

As most of browsers on handheld take care to have a more handly selector for this kind of <input>.

Caveats :

  • Does the step="1" attribute which triggers the seconds selector is really accepted everywhere ?
  • input and change events are triggered too early or too late ?
  • If a media is longer than 24 hours, you won't be able to select upper than the first 24 hours

Explode index.html

to use github pages features completely
Also, Chrome loads and caches so takes to much time when there is too much <audio> tags for him.

Better aspect for loading timeline

from dascritch/ondemiroir-audio-tag#53
Taken from the pdf reader of Firefox 55

#loadingBar .progress.indeterminate .glimmer {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: calc(100% + 150px);
    background: repeating-linear-gradient(135deg, #bbb 0, #999 5px, #999 45px, #ddd 55px, #ddd 95px, #bbb 100px);
    animation: progressIndeterminate 950ms linear infinite;

Hide fallback chapters lists when player display chapters

We may be interested to display a chapter lists by default (by example, in http://cpu.pm , we have #chapters) , waiting for th player to display his own.

  • prepare a way to hide it from an attribute in the chapters list ( data-cpu-playlist-for="audio-id" )
  • prepare a way to hide it from an attribute in the <cpu-audio> call ( playlist-fallback="playlist-id" )
  • hide only if a non-empty chapter list is loaded

Or use a simplier class added to host document.body, namely cpu_tag_«${audiotag.id}»_chaptered. Most flexible and easy to style.

Expandable mode="" on read

Why not having a player that expands when clicked on play for the first time ?

The player would have a button or compact aspect , then expands as default if the player is triggered to play.

it won't shrink later while the page is opened.

Some css vars settings won't be useful

Try those personnalization settings :

body {
	--cpu-background : transparent;
	--cpu-color : currentColor;
	--cpu-playing-background : transparent;
	--cpu-playing-color : currentColor;
}

When the mouse is over a link or button, the result is dirt, cannot be read.

Try to correct the issue if it's possible (filters ?), or document the impossibility.

Create a live chapter editor page

  • Having a player
  • Choosing an audio source URL
  • Create and naming chapters
  • Moving chapters, sorted by time
  • Deleting chapters
  • Showing HTML generated source
  • Showing HTML generated fragment
  • Showing markdown generated source
  • Showing wiki generated source
  • Integrate in .md file

Active chapter references in host page

Make references to named chapters in host page, to highlight during the play. It may be as a data-cpu-chapter="" attribute, or as a link <a href="#t=....">, but is there a specific notation of anchors in anchors ? ;)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.