PDA

View Full Version : mp3 cache



Sarah12345
01-04-2008, 04:27 PM
Hi Guys,

I have both Flash Streaming Server and Flash 8, but I can not find any tutorials that help me with my problem.
I am trying to make a player like the MYSPACE mp3 player (www.myspace.com/thehives) it has all the functions that I need and the audio does not cache. I have made radios that stream in audio but I am unable to get track timings or scrub the audio. I need a player that can stream mp3 from secure server, be able to scrub the audio track and get the tracks timings. Please help my head is cooking.

NTD
01-04-2008, 07:08 PM
Hi,

I can explain how to achieve this but it will take a decent understanding of AS on your end. Here is how I handle the slider position of an MP3 during play...


// setProp() is used by the volumeSlider
// and balanceSlider instances
// propMove() is used by the volumeSlider
// and balanceSlider instances. When movement
// occurs on the slider bars for these instances
// the appropriate method will be executed.
function propMove(active) {
if (active) {
this.onMouseMove = function() {
this.setProp(player.pos._x, this.currentProp, this.currentTarget);
updateAfterEvent();
};
} else {
this.onMouseMove = null;
}
}
// monitorSound() is used as onEnterFrame()
// event handler to move the pos instance
// on the controlBar's playSlider instance
// movement should only occur when the sound
// is playing, not when the user is dragging
// the pos instance on the playSlider instance
_global.monitorSound = function() {
var obj = _root.currentSound;
var startValue = this._parent.startValue;
var range = this._parent.range;
var percentPlayed = (obj.position / obj.duration);
if (obj.duration > 1) {
this.pos._x = (percentPlayed * range) + startValue;
} else {
this.pos._x = startValue;
}
};
// every time a new currentSound object is created in the
// loadFile() function, the sliders' methods and
// event handlers will be defined.
function defineSliders() {
controlBar.playStopButton.gotoAndStop("pause");
controlBar.playSlider.startSlider = function(active) {
if (active) {
this._parent.soundCtrl("pause");
} else {
this._parent.soundCtrl("play");
}
};
controlBar.playSlider.onEnterFrame = monitorSound;
}
// initialize the sliders with starting positions
controlBar.range = 225;
controlBar.startValue = 0;
controlBar.playSlider.pos._x = 0;


Here is a demo of the above code in action.....mind you, just a test MP3 player. This version uses PHP to load the file contents so it is a bit more dynamic than a regular MP3 player...

http://ntdesigns.net/miniPlayerPHP.swf

If you learn to use a LoadVars object, you can create album lists to load into a custom player like this one...

http://ntdesigns.net/ntPlayer/GroupyBandMate.swf

For more information regarding sound in Flash...

http://www.kennybellew.com/tutorial/

Hope it helps
NTD

Sarah12345
01-06-2008, 10:23 PM
Hi,

Thanks for this I think I understand where you are going, but the mp3s are caching in my temp folder.
Do you have a .fla that you can mail to me that would be so helpful.

Thank you.

NTD
01-07-2008, 06:53 AM
Hi,

Cacheing allows your browser to access local copies of items that repeat on many pages rather than having to continually download the same item over and over again. This allows for faster load times when dealing with large files like video or .mp3 files. As far as I know, Actionscript alone doesn't have the ability to prevent browser cacheing. However, if you find a situation where you don't want the files cached in the users temp files, you can use a couple of different meta tags in HTML and the Flash application needs to be embedded in the HTML page. If a user calls the .swf file directly, cacheing will still take place. As with most meta tags they should be placed within
the head tags of your document ...


<html>
<head>
<meta http-equiv="Pragma" content="no-cache">
<!-- Pragma content set to no-cache tells the browser not to cache the page
This may or may not work in IE -->

<meta http-equiv="expires" content="0">
<!-- Setting the page to expire at 0 means the page is immediately expired
Any vales less then one will set the page to expire some time in past and
not be cached. This may not work with Navigator -->

<title>CodeAve.com(No Cache)</title>
</head>


The content on this site will teach you everything you need to know about creating an advanced .mp3 player...
http://www.kennybellew.com/tutorial/

I am fairly certain my demo files would confuse you more than help. The mini player is incomplete and I havn't taken the time too comment on or optimize the code. The GroupyBandMate demo is a FlashMX creation and uses quite a bit of code as there are several built in options beyond just an MP3 player. I also use a few methods differently than many of the tutorials on kenny's site. I created my versions before I found his useful tutorials. If it is something for myspace, you might try a google search for free mp3 players......maybe something like this that you can simply embed...

http://www.myflashfetish.com/

Sarah12345
01-07-2008, 09:43 AM
Hi, I have tried the code but the mp3s still seem to cache. The reason I can not let the audio cache is because it is exclusive and I do not want it to be ripped and sold on. The way myspace does is seems to have that problem resolved. All the audio streams in but never caches.

NTD
01-07-2008, 08:22 PM
Hi,

I have only briefly looked into this issue as I dont mind file cacheing. In fact, it speeds up many of my larger applications. However, I did a bit of research and it appears that blocking a user from cacheing online Flash files is nearly impossible with all browswers. Some code works for stopping some browsers but apparently not all. I could not find any viable solution for stopping Firefox from cacheing files. It appears that the only sure fire way is to use the Flash Communication server.......which is a good bit of money, but ...

"Audio and video content streamed to Flash clients via Flash Media Server is not cached on local client machines. Deliver mp3 files and other media safely and securely knowing that your website visitor will not be able to go to their Temporary Internet Files folder and obtain your media file assets."

Other than that, I found one piece of code that looks promising but I have not had time to test it...



// Prevents caching of loaded files (TXTs, SWFs, XMLs etc...)
// Latest version (1.1)
String.prototype.noCache = function(){
var isSWFinHTML = (_level0._URL.indexOf("file:///")==-1);
var isURLlocal = (this.indexOf("://")==-1);
if (isSWFinHTML || !isURLlocal){
this += (this.indexOf("?")==-1) ? "?" : "&";
this += "noCache=" + (new Date().getTime());
}
return this;
}

// Old version (1.0)
String.prototype.noCache = function(){
if ((_root._URL.substr(0,5)).toLowerCase()!="file:"){
if(this.indexOf("?")==-1){
return this+="?noCache="+(new Date().getTime());
}else{
return this+="&noCache="+(new Date().getTime());
}
}else{
return this;
}
}


The final option that I came across is modifying the http.conf for Apache on your server with...again....untested...



ExpiresActive On

header append cache-control: "no-cache"

header append pragma: "no-cache"

header append expires: "-1"


That should prevent cacheing directly from your server.

hope it helps
NTD

blitzzz
02-18-2008, 05:05 PM
for the record. MP3s stream alot better if inside a .swf and on the main timeline. flash was built on streaming tech. you don't need a streaming server if done that way. + those .swf files will steam a heck of alot smoother. and at a higher quality. just a note.

blitzzz
02-18-2008, 05:09 PM
to prevent cache of a flash file you call it with a random number in the query string. myFile.swf?rand=(therandomNumer) the will work on all browsers. a browser does not read the query string it looks at it as a new file. that is the typical way of not-caching any file like an xml file or whatever. Same with flash. don't need that fancy function just a solid random number. the date + time is about the only thing that is typicaly used.

NTD
02-18-2008, 05:12 PM
Hi,

Actually, the point of this post was not how to "stream" mp3's, which is a bit of a misnomer. Flash doesn't actually "stream" as video does. It uses a similar technology known as "progressive download". While similar to streaming, it is really just a speed limit that allows a portion of the file to play while the remains of the file continue to load. For a more accurate definition, do a google search on "progressive downloading" and "streaming downloading". The whole point of this thread is how to play an .mp3 file so that it is not cached in the users browser. Anything that is cached is retainable by the user. This particular thread dealt with streaming copyrighted material so that the browser wont cache it. The only way I truely know how to achieve this is with the Flash communication server as it does not cache content. Adding a random number to an imported file means you get the latest version from the server, it does not prevent cacheing.

NTD

blitzzz
03-03-2008, 11:33 AM
lol. sorry about that. I guess i did not read , jumped the gun and posted.

i would have to agree with your post.

sorry if i caused any confusion..

blitzzz
03-03-2008, 12:42 PM
- edit - removed.