Playing audio file in jsp - html

1) Is there a way in java to stream an audio file from ftp on my jsp page?
2) How can I play an audio file in jsp without audio file being download on client browser (like live stream) - temporary internet files
please help with some code example

Streaming audio from a file does not have anything to do with the JSP itself.
You want to embed your audio file into the page using HTML tags. You can do this directly like:
<embed src="audiofile.mp3">
Or build something a bit more fancy using a Flash movie as an audio player, or find a JavaScript library. Here is a page on how to do it with various methods.
The JSP can provide the audio file name and perhaps other options, but that's all it has to do -- the rest is handled by plain old HTML tags.
You can find more information by searching the Web for the terms "embed" and "audio".

If you're already on HTML5, just use <audio> element, See also the HTML Dog tutorial.
<audio src="file.wav" controls="true" />
If you're not on HTML5 yet, audio in a webbpage is usually to be included by the HTML <embed> element (which uses the platform default player) or the HTML <object> element (wherein you can specify a more specific player for which the webbrowser can eventually automagically download the necessary plugin software).
<object data="file.wav" />
Either way, it should point to an URL which returns the audio stream. This can be just a static file in the public webcontent, next to the JSP file. E.g. http://example.com/context/file.wav. But when the audio file is stored outside the public webcontent or in a database, then you'd like to stream it via a Servlet. Basically just get an InputStream of it (using e.g. FileInputStream) and then write it to the OutputStream of the response along a correct set of response headers.
Noted should be that JSP is irrelevant in this particular question. It's just a view technology providing a template to write HTML in and send it to the webbrowser.
That said, websites which plays audio are generally considered annoying and generally scare off visitors. Keep this in mind if you consider User Experience important.

Related

How can I embed a audio player into a wix website?

I am trying to add an audio player to my Wix website. I want the audio player to play different files that can change dynamically by changing the url of the audio file.
There are a number of audio players that I could potentially use: https://freefrontend.com/css-music-players/
I am just not sure how to include them.
Which code needs to be included in the HTML iframe in Wix?
Which code needs to be added in the developer console or as a function?
Which files needs to be stored and can I store them on github?
An example of how to do it will really be appreciated.

how html5 <audio> tag is responded by web servers

Hi,
I developed a simple web server based on an open source C++ project.
In this web server there are a lot of wave files which I would like to show to web clients by using tag of HTML 5.
I added wave files like following sample in html files which are sent to web browsers.
<audio controls>
<source src = "sound.wav" type="audio/wave">
</audio>
But Now I would like to know how web servers handle tag and send stream data to web clients when web clients push play button.
I need to implement it from scratch in my web server.
I read a lot of posts but most of them just handle client side issues.
I need to deeply know how server side of a request is handled.
Best Regards
AS you can see in MDN doc https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
The HTML element is used to embed sound content in documents.
It may contain one or more audio sources, represented using the src
attribute or the element; the browser will choose the most
suitable one.
The stream is not send to web clients when web clients push play button but is send when the page is loaded (lile all the media in a web page)
you can control the execution using some attribute like :
autoplay
A Boolean attribute; if specified (even if the value is "false"!),
the audio will automatically begin playback as soon as it can do so, without waiting for the entire audio file to finish downloading.
buffered
An attribute you can read to determine which time ranges of the media have been buffered.
This attribute contains a TimeRanges object.
preload
This enumerated attribute is intended to provide a hint to the browser about what the author thinks will lead to the best user experience. It may have one of the following values:
none: indicates that the audio should not be preloaded;
metadata: indicates that only audio metadata (e.g. length) is fetched;
auto: indicates that the whole audio file could be downloaded, even if the user is not expected to use it;
the empty string: synonym of the auto value.
Serving a file is something I bet you already know. To serve audio streaming, there are streaming protocols. One is ShoutCast and here you have a nice example in Python.
https://github.com/inforichland/PyCast

Embed code html to play rtmp stream with additional attributes?

does any one know the way to play, rtmp stream with attributes embded on a website?
Also if i have:
rtmp://$OPT:rtmp-raw=rtmp://xx.xx.xx.xx/live?idp=4050/rer_835660 playpath=rofl swfUrl=http://www.somewww.com/tv/swf/player.swf?file=redtofile&autostart=true&/2/3 live=1 pageUrl=http://www.somewww.com/tv/get_file.php
the real rtmp link is:
rtmp://xx.xx.xx.xx/live?idp=4050/rer_835660/rofl
some of rtmp will play if there is no token for swf player protection. That is why i need swfUrl and pageUrl added and sometimes Decrypt option.
Is it even possible? I know that vlc have some issues with playing such as url's.
//edit:
I know that my link does play in SimpleTV but i have to get it every time it changes. I have written php script so it fetches actual link for me as soon as I open my webpage. So i know its correct.
Just need to find way to play it, with anything, except SimpleTV.
Preferably Embed code for website, normal rtmp links i play via vlc plugin, but it does not support such as long rtmp links, example shown above. I might be wrong? That might be me could phase or construct correctly rtmp link.

How to play .ts files (video/MP2T media type) in Browser?

I have one .m3u file that points to several .ts files (all in akamai).
Because we give to akamai a live stream, they convert it to these .ts files each of 10s. I see that the m3u files are easy to understand, but I can't find a browser based (flash, html5 or native plugin) player for these files.
If I give to vlc the link of the m3u file, vlc plays all the .ts files one after another as if it where only one big file. I want to use flash or something similar to be able to play in browser, the same way vlc can play those .m3u files.
Is this possible ?
You are basically talking about Apple's HLS format.
You can use an html5 object in your web page. You can use http://osmfhls.kutu.ru/ flash plugin. You can use jwplayer. There are more choices (e.g. flowplayer).

HTML5 Video tag as URL

I am learning the new HTML5 tags, and have a question about the video tag that I cannot seem to find a good example/answer for.
Can I provide a source as a URL, or does the source have to route from the web server? I am just trying to play with an example to see what it looks like, and use a youtube video as the source. Is this possible?
The source can indeed be a valid URL, which of course in this case needs to be a URL to a valid video file.