How to override HTML5 audio element to allow playing local files (file///)

5,052 views
Skip to first unread message

coder_at_n

unread,
Dec 9, 2010, 9:01:23 PM12/9/10
to Chromium-extensions
Hi there,

Motivation: I am trying to build a website to create LRC lyrics
(synchronized) of audio files, it would be a major waste of bandwith
to upload each one. Due it's security policy, chromium does not allow
it. The local file should be copy-pasted into a textarea, then loaded
to the player using javascript (this part already works). code: <audio
src="file:///home/user/Music/File1.mp3" ></audio>

Workarounds: There are some extensions which allow local links to
work, but are based on click event, which audio element doesn't use.

Question: Do you think that this could be solved by an extension? In
that case, could you give me some advice of which API should I take a
look?

Thanks for reading.

PhistucK

unread,
Dec 10, 2010, 1:02:04 PM12/10/10
to coder_at_n, Chromium-extensions
Perhaps you can use the FileReader API (they will have to select the files off the computers by having a <input type="file"/>) and the Blob API and createObjectURL to load the files.
For more information and links to the relevant specifications (for API reference), see the web platform status page here.

PhistucK




--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


coder_at_n

unread,
Dec 10, 2010, 4:59:37 PM12/10/10
to Chromium-extensions

Great, i've got it, taking this new approach is pretty easier ( i was
wondering about using a java applet )
This is how I've solved it, may it help someone

<script type='text/javascript'>
function handleFiles(files){
var file = window.createObjectURL(files[0]);
document.getElementById('audioPlayer').src = file;
}
</script>
<audio id='audioPlayer' controls ></audio>
<input type='file' id='selectedFile'
onchange='handleFiles(this.files)' />

damn simple! thanks ☆*PhistucK*!

On Dec 10, 7:02 pm, PhistucK <phist...@gmail.com> wrote:
> Perhaps you can use the FileReader API (they will have to select the files
> off the computers by having a <input type="file"/>) and the Blob API and
> createObjectURL to load the files.
> For more information and links to the relevant specifications (for API
> reference), see the web platform status page
> here<https://sites.google.com/a/chromium.org/dev/developers/web-platform-s...>
> .
>
> ☆*PhistucK*
>
>
>
>
>
>
>
> On Fri, Dec 10, 2010 at 04:01, coder_at_n <ignas...@gmail.com> wrote:
> > Hi there,
>
> > Motivation: I am trying to build a website to create LRC lyrics
> > (synchronized) of audio files, it would be a major waste of bandwith
> > to upload each one. Due it's security policy, chromium does not allow
> > it. The local file should be copy-pasted into a textarea, then loaded
> > to the player using javascript (this part already works). code: <audio
> > src="file:///home/user/Music/File1.mp3" ></audio>
>
> > Workarounds: There are some extensions which allow local links to
> > work, but are based on click event, which audio element doesn't use.
>
> > Question: Do you think that this could be solved by an extension? In
> > that case, could you give me some advice of which API should I take a
> > look?
>
> > Thanks for reading.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>
> > .

PhistucK

unread,
Dec 11, 2010, 3:04:00 AM12/11/10
to coder_at_n, Chromium-extensions
Wow, I never imagined it to be so simple myself. :)
I will certainly keep that in mind as well.

Thank you for the update. :)

PhistucK



To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
Reply all
Reply to author
Forward
0 new messages