Using JavaScript to read files stored on a user's computer - javascript

I'm building a website which has a music player that can currently play files stored on the server. I'm using soundManager2 to play the files.
What I would like to do is have the player also play files stored on a user's computer, which may not be possible and will probably hit security risks if it is.
This is a bit of the code I use to plays the files:
currentTrack = soundManager.createSound({
id: "Track",
url: file_location+".mp3",
});
Then soundManager2 does its magic. As the location of the file is a variable, I was hoping that if a user were to specify the location of an mp3 on their computer it could be put into the variable and played in soundManager, in the same way it finds files on our server and plays them. My thinking is that as soundManager uses javascript and flash, or HTML5 it's all client side so there wouldn't be any security issues and it could just be 'streamed' from their computer without any strain on our bandwidth.
How can this be done?

AFAIK, soundManager will not help you. However, Flash Player 10+ has the FileReference class, which can be used to load an user selected file directly to a SWF, which then can be played by Flash Player. Here is a description and a working example of how to do it: http://www.multimediacollege.be/2011/04/how-to-play-a-local-mp3-file-in-flash/

Related

Creating an mp3 player for GWT

I am creating a web application with GWT that needs to be able to upload and manipulate (play, pause, scroll, etc.) mp3 files from the user's computer. It also has to be able to add time stamps, whose information can later be downloaded. I can't seem to find any simple way to add an mp3 player to my application. Is there some widget pack or something I can download without having to develop it all on my own?
http://www.gwtproject.org/javadoc/latest/com/google/gwt/media/client/package-summary.html ?
The only thing you will be able to do in GWT client side is playing these mp3 files.
Adding timestamps, information you will have to do serverside.

How can I track the number of times an audio file from my server has been played?

I have audio files (.mp3 and .wav format) saved on my server. They're normally supposed to be played through a webpage and I can track how often that page is opened.
But people can now refer directly to that sound file's link on my server and play it. How do I track the number of times these audio files are played?
An example: Normally user access the recording through this page, https://namedrop.io/keshavmalani But now a person may choose to integrate their NameDrop recording into something else using the direct recording link: https://namedrop.io/profile/audio/km.mp3 and ideally I want to be able to track it.
I don't have a redirect to the audio file setup. Recommendation on how I would implement this without causing slowdown? I'm a beginner - intermediate coder.
Answer is here: How do I track file downloads
By: #w-ll (https://stackoverflow.com/users/146637/w-ll)
Thanks to #DanielProtopopov for pointing it out

Web Audio API and Audio Download and Protection

I'm reading a book about Web Audio API.
In the book it states that to play and load a sound using the WEB AUDIO API, there are 4 steps that needs to be taken:
1.) Load the sound file with XHR and decode it. (Will end up with a 'buffer')
2.) Connect the buffer to audio effects nodes.
3.) To hear the sound, connect the last node in the effects chain to the destination.
4.) Start the sound.
My question is...given these 4 steps, is there a way for the user of the website that uses the Web Audio to download the audio/audios played on the website???
If so, how does one prevent this.
or does it being 'buffered' prevent it from being illegally downloaded?
I would like to find a way to protect the audio files I use inside my game/app that I put up on the webpage that are played with the Web Audio API.....
Thank you....
EASILY save it, no. But 1) if it's being transferred as an MP3, etc file the user can go into their network cache and copy it; there's no inherent DRM or anything. 2) Even if the sound was being generated completely from scratch (e.g. mathematically) the user could use a virtual audio device like Soundflower to save the output.
So no, it's not really possible to prevent the user from saving audio files.

How to play local XviD (.avi) files that are chosen by the user in the browser?

So I'm building a web application, and in part of the application the user should choose an XviD (.avi) video file from his machine, to be played in the browser (without uploading it). I decided to use Flash for this.
Now I have two questions about this:
Which Flash video player is free to use and capable of doing this?
How should I let the user choose a video file, and how can I link the Flash video player to the file?
I think you can't. The Flash plugin don't have enough privileges to access the user's local file system.

How do streaming videos work?

So I have some videos in .flv format which I'd like people to be able to view from my site, without being able to download them. So far Flowplayer seems like the best choice for the actual flash player.
However, I've been looking into this video streaming thing, as its supposed to make the videos very fast to view and allows seeking to the middle of the video, etc. What do I need to make it work, do i need to have some special server software for this? And how can I integrate with this software using the javascript/PHP code that i'll use to display the videos?
Thanks.
Good news! You don't need special software, most reasonable web servers can do all of that out of the box. What you're describing, and what Youtube and the rest do, isn't streaming actually. It's called progressive download.
Basically the SWF player (flowplayer in your case) is downloading the FLV video, and playing what it has downloaded so far. To skip to some video that it has already downloaded, it seeks in the downloaded file. To skip beyond what has already been downloaded it discards the downloaded file and starts a new download, but it asks the HTTP server to start giving it the file at a certain offset. Thankfully, most HTTP servers can do this out of the box.
So you just need to put the FLV files somewhere that's publicly available to download via HTTP (just test this with your browser). Assuming you put flowplayer at /flowplayer.swf on your site, and the video is /2girls1cup.flv you would insert this into your page:
<script src="http://static.flowplayer.org/js/flowplayer-3.0.6.min.js"></script>
<!-- Edit this with the width and height to display the video -->
<a
href="/2girls1cup.flv"
style="display:block;width:425px;height:300px;"
id="player">
</a>
<!-- this script block will install Flowplayer inside previous anchor tag -->
<script language="JavaScript">
flowplayer("player", "/flowplayer.swf");
</script>
I took this example from the flowplayer demos page where there's lots more examples of lots of ways to customize flowplayer, the way it behaves and is displayed.
There are two ways in which an actual streaming server is better. One is for doing multicasts of a stream, in which all clients are at the same place in the video, which is easier on the server. The other is being able to deliver a number of different encodings of the same stream, so that, for example, clients can the video at a bitrate that best matches their playback capability.
A lot of companies bet a lot of money that this would be very important for video to take off on the web. It looks like all of them are wrong. Streaming servers are mostly used in the enterprisey world, which might explain their enterprisey prices.

Categories

Resources