Streaming Icecast through flash - actionscript-3

Hi my name is Tamer and this is very first post in stackoverflow as far as I know. :)
I've been searching this for an issue of mine for a while but haven't found any solutions yet. I want to forward my radio broadcast from it's original host to my embedded flash player once the play button is hit. Is it possible via action script (flash - as3) ? My broadcast is in Icecast format, and I'm playing mp3 but my mount point is not exactly /listen.mp3. It has some more extention like ?auth and some random fixed stuff (I mean, there are some other things at the end of the auth part, but it's same all the time like a fixed link).
Thanks for your help and time!

Yes, you can play your stream with Flash. It doesn't matter what your mount point is. Just plug in the real URL for the stream. The file name extension and what not doesn't matter.

When using the above answer high memnory use may be an issue for your viewers as the "Sound" variable downloads the data while playing.
Would be better off using progressive play/download but would have to change your streaming format from mp3 as it only allows for M4A streaming (AAC audio data in an MP4 container).
var netConnection:NetConnection = new NetConnection();
netConnection.connect(null);
var netStream:NetStream = new NetStream(netConnection);
netStream.play(“http://your.stream.url/stream.m4a”);
Just my 2cents :)

Related

How to record video by actionscript 3 ?

Can we record video (capture/ streaming) by actoinscript 3 ? and upload the same to server ?
Anybody have any reference link for it ?
your help will be appreciable
Thank you
Yes, there is support for recording video and surely you can send this data to the server.
There are many tutorials available, you can find them with a simple google search:
https://influxis.com/simple-as3-recorder/
https://code.google.com/p/flvrecorder/ --- has a sample
http://www.purplesquirrels.com.au/2012/12/record-and-play-back-video-with-air-for-ios-on-ipad/
and many, many others.
If you want to use free server, where to send video to, I suggest to look into Red5, it seems that it's not supported for a while now, but the latest releases are running well.
Red5: http://www.red5.org
You can capture audio and video from a webcam using Flash/ActionScript.
The encoded audio and video data is streamed (through rtmp) from the Flash client running in a browser to a media server like Red5, Wowza and AMS where it is saved in .flv, mp4 or .f4v video files.
For the exact client AS3 code see this answer.

Audio tag security in html5

Long version:
I use html5 audio tag to play mp3 files on my website. With Flash I can stream mp3's and secure it for 95%.
With html5 it is easy to find out the mp3 location and just download it from there. Even if I secure it with unique hashes it is not hard to inspect the network tab in chrome and see the mp3 url with hashes.
I was wondering if there are other ways to secure the mp3 from being ripped and if it is worth the time. For example bandcamp does generate unique hashes but it is still very easy to download the mp3. For youtube you got download websites that can proces the flv stream and rip the audio and save it for the user as mp3 format.
The first layer of security I can think of is change the extension of mp3 files to .txt or another common format.
95% of the users don't spot the extension because it is hidden by default on windows and apple. This will prevent the first 95% of the users to spot and play the mp3 file.
Short Version
Any suggestions to prevent users from stealing mp3 files while using html5 audio tag.
Short Answer
No.
Renaming the audio file to .txt is not going to do anything to help the security of your mp3 audio file. If anything, it is going to cause you even more issues, because now, your mp3 audio file is going to be sent with the incorrect MIME type, which may cause issues with the browser's built in audio player.
The best suggestions that I can provide you is:
Make sure that your checking the REFERER http header, make sure that it is coming from the page that has the mp3 player on it.
Protect the mp3 file with a unique hash.
Don't allow the same hash to be downloaded twice*
*Note that even doing this could cause issues, for example, what happens if the user reopens a tab from cache, plays the file again, and the mp3 file is not cached?
And finally, at the end even after your mp3 file is the most protected mp3 file in the history of IIS and Apache -- what is stopping me from just opening up Adobe Audition, and recordinging the audio stream?
Although you are correct about Bandcamp's MP3 audio stream, the mp3 is not as high quality then just a normal download after purchasing an album.
The fact that even Google does not really have any decent protections on it's video streams should say something. A company that generates billions of dollars from video views on YouTube can't even make (or better put -- has not bothered to put in place) any viable methods for protecting their videos.
Kind of.
Grooveshark send a POST request to a server-side script for the MP3 that is being streamed which makes it very difficult to just access and spoof without dynamically creating a POST request yourself - especially seeing as you would have to then attempt to store the audio file that is collected. But you can use the new AudioContext to help solve this for most modern platforms...
I used a great example from HTML5Rocks.com to alter the headers used as follows:
var dogBarkingBuffer = null;
// Fix up prefixing
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var context = new AudioContext();
function loadDogSound(url) {
var request = new XMLHttpRequest();
request.open('POST', url, true);
request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
request.responseType = 'arraybuffer';
// Decode asynchronously
request.onload = function() {
context.decodeAudioData(request.response, function(buffer) {
dogBarkingBuffer = buffer;
}, onError);
}
//this is the encryption key
request.send("key=98753897358975387943");
}
Related
As you can see I am also sending a key value which could possibly be part of a public/private pair too. This should put anyone off attempting to intervene - other than simply recording the MP3 as it's playing, of course, but what could possibly stop that in any environment inside or out of a computer?
You could make the MP3s themselves unattractive. Some ideas:
Don't include album art, album info, etc. in your files (id3 tags). Even better, fill out all id3 tag fields with something like "This file is from myMusicSite.com".
Split your files into several smaller pieces, and then play them in sequence in the browser. Having to download all the individual pieces will make your files much less attractive. You may have problems with gapless playback, not sure how well that's supported though.
Encode and play them as a video, maybe with your logo or something as the video stream. The resulting files won't be much larger, esp. if you use a static image. This will mean that users can't play your files on mp3 players, phones, etc. easily.
Whisper your domain name or website name in the recordings a few times, as mentioned in the comments.

How to record audio and save it in mp3 format in AS3 (Adobe Air2.5)?

I am building one desktop application in Air2.5, which needs to record and save audio.
In AS3 (Specially with Air 2.5), is it possible to record and save audio in mp3 format?
Here is library to convert audio to mp3 :
https://github.com/kikko/Shine-MP3-Encoder-on-AS3-Alchemy
To record audio informations are here :
http://titansturf.in/2010/02/08/fetching-data-from-the-microhpone-and-recording-sound/
This also should be usefull :
http://suzhiyam.wordpress.com/2011/04/14/as3-microphone-record-and-save-as-wave-file/
And about save read this :
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html
I use this pre-built Flash + JavaScript solution. It costs money, but works great. It will record, encode to MP3, and upload via PHP:
http://recorder.denniehoopingarner.com/
Here is a free related example that will use Flash to encode to OGG:
http://labs.byhook.com/2011/02/22/ogg-vorbis-encoder-decoder-for-flash/
I sat next to some Google programmers at a recent hackathon in SF who shared with me that Chrome will have the audio recording flag turned on by default starting April 2013 which technically makes recording in pure JS possible, but I have not seen a solution to encode and upload to a server yet. Good luck!

HTML: How to start Sound playback from URL mid-file without buffering all sound data to that point

I have a long mp3 file hosted on a standard apache server (30 minutes long so far, but I would like it to work with longer sounds too).
I'd like to start playback of this audio within at a specified point.
When attempting to use Flash Actionscript 3, my basic tests show that ALL the audio from the start to the position I choose is buffered before playback (Sound.bytesLoaded was my friend here). If I start one second in, it takes about 3 seconds to start playback, 30 seconds in, takes about 25 seconds.
Obviously with a really long mp3, like skipping playback to the middle of a 3-hour audiobook, this isn't going to be practical.
Here's the ActionScript 3.0 code I'm using:
button.addEventListener(MouseEvent.MOUSE_DOWN, function():void {
var s:Sound = new Sound();
var req:URLRequest = new URLRequest("http://example.com/audio.mp3");
s.load(req);
s.play(30 * 60 * 1000); // start 30 seconds in.
}
);
Anyone know if this is even possible in Flash?
If not, is it even possible to do this from a web page without installing any server-side solution?
Thanks a lot.
As I understand it, it is a question of regular "progressive download" over HTTP vs streaming.
In a standard setup, a regular HTTP server and Flash Player cannot skip past parts of an mp3 or video, all the data up to that point has to be downloaded first, as you describe.
One way to enable skiping/seeking is using a streaming server like Adobe's Flash Media Streaming Server or the open source alternative Red5 to serve the mp3's.
But there are also ways to set up so called "pseudostreaming" on a HTTP server:
http://flowplayer.org/plugins/streaming/pseudostreaming.html

How to get netstream bytesLoaded and bytesTotal from streaming .mp4?

I have a flex 3 app that uses netstream and a video object to stream .mp4 movies. I want to use the bytesLoaded and bytesTotal properties of the netstream to display the buffering information. I would also like to get any information about the number of frames that are dropped if possible.
When I've tested on .flv I'm able to get the information without a problem, but it doesn't seem to work on .mp4.
Is it possible to get this information streaming .mp4? Is there some configuration that I'm missing to make things work the same for .mp4 as .flv?
Thanks!
edit: I should also mention that the streaming is done over RTMP
I figured out that when using RTMP you can't get the byte information because the data isn't downloaded, it's purely streaming.
So instead I'm using the buffering info instead
Math.min(Math.round(ns.bufferLength/ns.bufferTime*100), 100);