Zurück   Flashforum > Flash > Flash Fortgeschritten > Flash CS3 Professional

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 24-03-2011, 13:52   #1 (permalink)
Style Freak
 
Registriert seit: Nov 2004
Ort: Radolfzell
Beiträge: 615
mjpeg Klasse überarbeiten mit Reload

hi ich wollte mich mal erkundigen ob man in diese mjepg klasse einen reload einbauen kann so das das bild nach vorgegebener zeit neu läd. aber mir nicht permanent den ganzen arbeitsspeicher zumüllt.

PHP-Code:
package 
{
    
import flash.display.Loader;
    
import flash.events.Event;
    
import flash.events.ProgressEvent;
    
import flash.net.Socket;
    
import flash.utils.ByteArray;
    
import com.dynamicflash.util.Base64;
    
    
/**
     * This is a class used to view a MJPEG
     * @author Josh Chernoff | GFX Complex
     * 
     */
    
public class  MJPEG extends Loader
    
{
        private var 
_user:String;                                     //Auth user name
        
private var _pass:String;                                    //Auth user password
        
        
private var _host:String;                                     //host server of stream
        
private var _port:int;                                      //port of stream        
        
private var _file:String;                                    //Location of MJPEG
        
private var _start:int 0;                                 //marker for start of jpg

        
private var webcamSocket:Socket = new Socket();                //socket connection
        
private var imageBuffer:ByteArray = new ByteArray();        //image holder
        
        /**
         * Create's a new instance of the MJPEG class. Note that due a sandbox security problem, unless you can place a crossdomain.xml 
         * on the host server you will only be able to use this class in your AIR applications.
         * 
         * @example import MJPEG;
         *            var cam:MJPEG = new MJPEG("192.168.0.100", "/img/video.mjpeg", 80);
         *            addChild(cam);
         *            
         * @param    host:String | Host of the server. Do not include protocol 
         * @param    file:String | Path to the file on the server. Start with a forward slash
         * @param    port:int    | Port of the host server;
         * @param    user:String | User name for Auth
         * @param    pass:String | User password for Auth
         */
        
public function MJPEG (host:Stringfile:Stringport:int 80user:String nullpass:String null )
        {
            
_host host;
            
_file file;
            
_port port;
            
_user user;
            
_pass pass;
            
            
webcamSocket.addEventListener(Event.CONNECThandleConnect);
            
webcamSocket.addEventListener(ProgressEvent.SOCKET_DATAhandleData);
            
webcamSocket.connect(hostport);
            
        }
        
        private function 
handleConnect(e:Event):void 
        
{
            
// we're connected send a request
            
var httpRequest:String "GET "+_file+" HTTP/1.1\r\n";
            
httpRequest+= "Host: localhost:80\r\n";
            if(
_user != null && _pass != null){
                            var 
source:String String(_user ":" _pass);
                            var 
auth:String Base64.encode(source);
                            
httpRequest += "Authorization: Basic " auth.toString()+ "\r\n";    //NOTE THIS MAY NEEED TO BE EDITED TO WORK WITH YOUR CAM
                        
}
            
httpRequest+="Connection: keep-alive\r\n\r\n";
            
webcamSocket.writeMultiByte(httpRequest"us-ascii");
        }

        function 
handleData(e:ProgressEvent):void {
            
//trace("Got Data!" + e);
            // get the data that we received.

            // append the data to our imageBuffer
            
webcamSocket.readBytes(imageBufferimageBuffer.length);
            
//trace(imageBuffer.length);
            
while(findImages()){
            
//donothing
            
}

            
        }


        private function 
findImages():Boolean
        
{

            var 
x:int _start;
            var 
startMarker:ByteArray = new ByteArray();    
            var 
end:int 0;
            var 
image:ByteArray;

            if (
imageBuffer.length 1) {
                if(
_start == 0){
                    
//Check for start of JPG
                    
for (ximageBuffer.length 1x++) {
                         
                        
// get the first two bytes.
                        
imageBuffer.position x;
                        
imageBuffer.readBytes(startMarker02);
                        
                        
//Check for end of JPG
                        
if (startMarker[0] == 255 && startMarker[1] == 216) {
                            
_start x;
                            break;
                            
myCam.stop();
                        }
                    }
                }
                for (
ximageBuffer.length 1x++) {
                    
// get the first two bytes.
                    
imageBuffer.position x;
                    
imageBuffer.readBytes(startMarker02);
                    if (
startMarker[0] == 255 && startMarker[1] == 217){
                        
                        
end x;
                                        
                        
image = new ByteArray();
                        
imageBuffer.position _start;
                        
imageBuffer.readBytes(image0end _start);
                                        
                        
displayImage(image);
                                        
                        
// truncate the imageBuffer
                        
var newImageBuffer:ByteArray = new ByteArray();
                        
                        
imageBuffer.position end;
                        
imageBuffer.readBytes(newImageBuffer0);
                        
imageBuffer newImageBuffer;

                        
_start 0;
                        
0;
                        return 
true;
                        
myCam.start();
                    }
                }
            }

            return 
false;
        }

        private function 
displayImage(image:ByteArray):void
        
{
            
this.loadBytes(image);
        }
        
    }
    

muss leider dazusagen das ich mich mit as3 erst seit gut 2 wochen sehr unregelmäsig befasse, und somit noch keine erfahrungen habe. kann mir da jemand evtl nen anstoß geben wie und wo ich was ändern muss?
__________________
Mit dieser Signatur hast du eben mal so unnötige 4Kb herrunter geladen!
ciberjoerg ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
mjpeg-bilder in flash darstellen johaha Flash MX 0 03-11-2006 19:20
Website Überarbeiten FMK Flash MX 6 06-07-2006 13:06
Logo überarbeiten M@RIO Bitmap-Programme 6 24-09-2004 20:11
Flashbanner Tutorial überarbeiten. Lightstormer Flash MX 2 06-06-2003 23:41


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:09 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele