Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 15
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2008
    Messaggi
    101

    JMF DataSink: java.lang.RuntimeException: No permission to write files from applets

    Ciao a tutti!!
    dovrei realizzare un applet che viene attivata da dei pulsati posti su una jsp , che da delle immagini crea un video .
    La libreria utilizzata è JMF
    Ho provato a realizzare l'applet fino ad adesso riesco attraverso il bottone start a realizzare dei screenshot poi con il bottone stop dovrei chiamare il metodo o classe che crea il video ma al momento della scrittura mi va in errore dicendo :

    codice:
    Impossibile creare il DataSink: java.lang.RuntimeException: No permission to write files from applets
    ma come è possibile se prima le immagini me le ha salvate???

    Ecco il codice:
    codice:
    import java.awt.*; 
    import java.awt.image.BufferedImage;
    import java.applet.*; 
    import java.io.File;
    import java.io.IOException;
    
    import java.net.URL;
    import java.net.URLClassLoader;
    
    import javax.imageio.ImageIO;
    
    // Implement Runnable, this will make it possible for threads 
    // to call the run method when activated. 
        public class mainApplet extends Applet implements  Runnable { 
        	int i=0;
        	
        	Thread threadFoto=null;
      	    boolean continua = false;
      	    boolean chiamato = false;
            
      	    public void start() {
              System.out.println("1");
              if(chiamato) continua= true;
             
              threadFoto = new Thread(this);
        	  threadFoto.start();
    		}
      	      
        	  public void stop(){
        		System.out.println("2");  
        		continua = false;
        		if(threadFoto != null){
        		   threadFoto.interrupt();
        		}
        		threadFoto=null;
        	  } 
        	  
        	 public void run(){
        		  System.out.println("3");
        		  
        		 while (continua){
        			 i++;
        			 System.out.println("3a");
        			 try {
    					scattaFoto(i);
    				 } catch (AWTException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				 } catch (IOException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				 }
        	      }
        	  }
        	 
        	  public void stopFoto(){
        		   System.out.println("stop Foto");
        		   stop();  
        		   System.out.println("Crea video");
        		   generaVideo.creaVideo();
        	  }
        	  
        	  public void startFoto() {
        		  System.out.println("1");
        		  chiamato = true;
        		  EventQueue.invokeLater(new Runnable(){
        	            public void run() {
        	                 start();
        	            }
        		  });
    		  }
        	  
        	  public void scattaFoto(int i) throws AWTException, IOException{
        	      BufferedImage screencapture = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );
        	      Point p= MouseInfo.getPointerInfo().getLocation();
    
        	      URLClassLoader urlLoader = (URLClassLoader)this.getClass().getClassLoader();
        	  	  URL fileLocation = urlLoader.findResource("cursor.gif");
        	  	
                  BufferedImage cursor= ImageIO.read(fileLocation);
        	      screencapture.createGraphics().drawImage(cursor, p.x, p.y, null);
        	      ImageIO.write(screencapture, "jpg", new File("c:/image/screencapture"+i+".png"));
        	} 
    }


    Continuaa...............

  2. #2
    Utente di HTML.it
    Registrato dal
    Mar 2008
    Messaggi
    101
    continua...................


    Questa è la classe che viene chiamata per realizzare il video

    codice:
    ----------------------------------------------------------------------------------------
    
    import java.io.*;
    import java.util.*;
    import java.awt.Dimension;
    import javax.media.*;
    import javax.media.control.*;
    import javax.media.protocol.*;
    import javax.media.protocol.DataSource;
    import javax.media.datasink.*;
    import javax.media.format.VideoFormat;
    
    /**
    * Questo programma prende una sequenza di immagini JPEG e le converte in un
    * file video QuickTime.
    */
    public  class generaVideo implements ControllerListener,
    DataSinkListener {
    
    public boolean doIt(int width, int height, int frameRate, Vector inFiles,
    MediaLocator outML) {
    
    ImageDataSource ids = new ImageDataSource(width, height, frameRate,
    inFiles);
    Processor p;
    try {
    System.err.println("Creazione del processor dal datasource…");
    p = Manager.createProcessor(ids);
    } catch (Exception e) {
    System.err.println("Impossibile creare un processor dal " +
    "datasource!");
    return false;
    }
    p.addControllerListener(this);
    
    // Mettiamo il Processor nello stato configurato in modo da poter
    // settare le opzioni del Processor
    p.configure();
    if (!waitForState(p, p.Configured)) {
    System.err.println("Configurazione del Processor fallita.");
    return false;
    }
    
    // Poniamo l'uscita del Processor di tipo QuickTime.
    p.setContentDescriptor(new ContentDescriptor(
    FileTypeDescriptor.QUICKTIME));
    // Settiamo il formato della traccia
    TrackControl tcs[] = p.getTrackControls();
    Format f[] = tcs[0].getSupportedFormats();
    if (f == null || f.length <= 0) {
    System.err.println("Questo formato non è supportato: "
    + tcs[0].getFormat());
    return false;
    }
    tcs[0].setFormat(f[0]);
    System.err.println("Il formato settato della traccia è: " + f[0]);
    
    // Realizziamo il Processor
    p.realize();
    if (!waitForState(p, p.Realized)) {
    System.err.println("Realizzazione del Processor fallita.");
    return false;
    }
    // Creiamo il DataSink
    DataSink dsink;
    if ((dsink = createDataSink(p, outML)) == null) {
    System.err.println("Creazione del DataSink fallita per il " +
    "MediaLocator: " + outML);
    return false;
    }
    dsink.addDataSinkListener(this);
    fileDone = false;
    System.err.println("Avviata la transcodifica..");
    // Avviamo il processo di transcodifica
    try {
    p.start();
    dsink.start();
    } catch (IOException e) {
    System.err.println("Errore di IO durante la transcodifica.");
    return false;
    }
    waitForFileDone();
    try {
    dsink.close();
    } catch (Exception e) {
    }
    p.removeControllerListener(this);
    System.err.println("...transcodifica terminata.");
    return true;
    }
    
    /**
    * Creazione del DataSink
    */
    DataSink createDataSink(Processor p, MediaLocator outML) {
    DataSource ds;
    if ((ds = p.getDataOutput()) == null) {
    System.err.println("Il Processor non ha un DataSource di " +
    "output. ");
    return null;
    }
    DataSink dsink;
    try {
    System.err.println("DataSink creato per il MediaLocator: "
    + outML);
    dsink = Manager.createDataSink(ds, outML);
    dsink.open();
    } catch (Exception e) {
    System.err.println("Impossibile creare il DataSink: " + e);
    return null;
    }
    return dsink;
    }
    
    Object waitSync = new Object();
    boolean stateTransitionOK = true;
    /**
    * Aspetta finché il Processor non è transitato nello stato desiderato.
    * Ritorna false se la transizione è fallita.
    */
    boolean waitForState(Processor p, int state) {
    synchronized (waitSync) {
    try {
    while (p.getState() < state && stateTransitionOK)
    waitSync.wait();
    } catch (Exception e) {
    }
    }
    return stateTransitionOK;
    }
    
    /**
    * Controller Listener.
    */
    public void controllerUpdate(ControllerEvent evt) {
    if (evt instanceof ConfigureCompleteEvent
    || evt instanceof RealizeCompleteEvent
    || evt instanceof PrefetchCompleteEvent) {
    synchronized (waitSync) {
    stateTransitionOK = true;
    waitSync.notifyAll();
    }
    } else if (evt instanceof ResourceUnavailableEvent) {
    synchronized (waitSync) {
    stateTransitionOK = false;
    waitSync.notifyAll();
    }
    } else if (evt instanceof EndOfMediaEvent) {
    evt.getSourceController().stop();
    evt.getSourceController().close();
    }
    }
    
    Object waitFileSync = new Object();
    boolean fileDone = false;
    boolean fileSuccess = true;
    
    /**
    * Aspetta finché non è terminata la scrittura del file.
    */
    boolean waitForFileDone() {
    synchronized (waitFileSync) {
    try {
    while (!fileDone)
    waitFileSync.wait();
    } catch (Exception e) {
    }
    }
    return fileSuccess;
    }
    
    /**
    * Gestore degli eventi del file writer.
    */
    public void dataSinkUpdate(DataSinkEvent evt) {
    if (evt instanceof EndOfStreamEvent) {
    synchronized (waitFileSync) {
    fileDone = true;
    waitFileSync.notifyAll();
    }
    } else if (evt instanceof DataSinkErrorEvent) {
    synchronized (waitFileSync) {
    fileDone = true;
    fileSuccess = false;
    waitFileSync.notifyAll();
    }
    }
    }
    
    public static void creaVideo(){
       int width = -1, height = -1, frameRate = 1;
        Vector inputFiles = new Vector();
        String outputURL = null;
        width =1024;
        height=768;
        frameRate=3;
        outputURL="file://c:/video/video.mov";
        int i=0;
          while(i<50){
              inputFiles.addElement("c:/image/screencapture"+i+".png");
              i++;
          }
    
        if (outputURL == null || inputFiles.size() == 0)
        prUsage();
        // Controlla l'estensione del file video desiderato.
        if (!outputURL.endsWith(".mov") && !outputURL.endsWith(".MOV")) {
        System.err.println("L'estensione del file video dovrebbe " +
        "essere .mov");
        prUsage();
        }
        if (width < 0 || height < 0) {
        System.err.println("Specificare la corretta dimensione dell'"
        + "immagine");
        prUsage();
        }
        // Controlla il frame rate.
        if (frameRate < 1)
        frameRate = 1;
        // Genera il media locator .
        MediaLocator oml;
        if ((oml = createMediaLocator(outputURL)) == null) {
        System.err.println("Impossibile creare il Media Locator: "
        + outputURL);
        System.exit(0);
        }
        generaVideo imgToMovie = new
        generaVideo();
        imgToMovie.doIt(width, height, frameRate, inputFiles, oml);
        System.exit(0);
    
    }
    
    
    static void prUsage() {
    System.err.println("Come avviare il programma: " +
    "java GeneratingVideoFromImages -w " +
    " <width> -h <height> -f <frame rate> " +
    "-o <output URL> <input JPEG file 1> " +
    "<input JPEG file 2> ...");
    System.exit(-1);
    }
    
    /**
    * Crea un MediaLocator a partire dalla url passatagli come argomento
    */
    static MediaLocator createMediaLocator(String url) {
    MediaLocator ml;
    if (url.indexOf(":") > 0 && (ml = new MediaLocator(url)) != null)
    return ml;
    if (url.startsWith(File.separator)) {
    if ((ml = new MediaLocator("file:" + url)) != null)
    return ml;
    } else {
    String file = "file:" + System.getProperty("user.dir")
    + File.separator + url;
    System.out.println("---------->FILE: "+file);
    if ((ml = new MediaLocator(file)) != null)
    return ml;
    }
    return null;
    }
    /**
    * Un DataSource per leggere i dati da una sequenza di file immagini JPEG
    * e memorizzarli in uno stream di buffer.
    */
    class ImageDataSource extends PullBufferDataSource {
    ImageSourceStream streams[];
    
    ImageDataSource(int width, int height, int frameRate, Vector images)
    {
    streams = new ImageSourceStream[1];
    streams[0] = new ImageSourceStream(width, height, frameRate,
    images);
    }
    
    public void setLocator(MediaLocator source) {
    }
    
    public MediaLocator getLocator() {
    return null;
    }
    
    public String getContentType() {
    return ContentDescriptor.RAW;
    }
    
    public void connect() {
    }
    
    public void disconnect() {
    }
    
    public void start() {
    }
    
    public void stop() {
    }
    
    public PullBufferStream[] getStreams() {
    return streams;
    }
    
    public Time getDuration() {
    return DURATION_UNKNOWN;
    }
    
    public Object[] getControls() {
    return new Object[0];
    }
    
    public Object getControl(String type) {
    return null;
    }
    }
    /**
    * Lo stream sorgente per scorrere l'ImageDataSource.
    */
    class ImageSourceStream implements PullBufferStream {
    Vector images;
    int width, height;
    VideoFormat format;
    float frameRate;
    long seqNo = 0;
    // indice della prossima immagine da leggere.
    int nextImage = 0;
    boolean ended = false;
    
    public ImageSourceStream(int width, int height, int frameRate,
    Vector images) {
    this.width = width;
    this.height = height;
    this.images = images;
    this.frameRate = (float) frameRate;
    format = new VideoFormat(VideoFormat.JPEG,
    new Dimension(width,height), Format.NOT_SPECIFIED, Format.byteArray,frameRate);
    }
    
    public boolean willReadBlock() {
    return false;
    }
    
    /**
    * Legge i frame del video.
    */
    public void read(Buffer buf) throws IOException {
    if (nextImage >= images.size()) {
    System.err.println("Lette tutte le immagini.");
    buf.setEOM(true);
    buf.setOffset(0);
    buf.setLength(0);
    ended = true;
    return;
    }
    String imageFile = (String) images.elementAt(nextImage);
    nextImage++;
    System.err.println("Lettura del file: " + imageFile);
    // Apriamo un random access file per la prossima immagine.
    RandomAccessFile raFile;
    raFile = new RandomAccessFile(imageFile, "r");
    byte data[] = null;
    if (buf.getData() instanceof byte[])
    data = (byte[]) buf.getData();
    if (data == null || data.length < raFile.length()) {
    data = new byte[(int) raFile.length()];
    buf.setData(data);
    }
    long time = (long) (seqNo * (1000 / frameRate) * 1000000);
    buf.setTimeStamp(time);
    buf.setSequenceNumber(seqNo++);
    raFile.readFully(data, 0, (int) raFile.length());
    buf.setOffset(0);
    buf.setLength((int) raFile.length());
    buf.setFormat(format);
    buf.setFlags(buf.getFlags() | buf.FLAG_KEY_FRAME);
    raFile.close();
    }
    
    /**
    * Ritorna il formato dell'immagine...che sarà JPEG
    */
    public Format getFormat() {
    return format;
    }
    
    public ContentDescriptor getContentDescriptor() {
    return new ContentDescriptor(ContentDescriptor.RAW);
    }
    
    public long getContentLength() {
    return 0;
    }
    
    public boolean endOfStream() {
    return ended;
    }
    
    public Object[] getControls() {
    return new Object[0];
    }
    
    public Object getControl(String type) {
    return null;
    }
    
    }
    }
    e la pagina che richiama l'applet è :
    codice:
    <applet code="mainApplet.class" archive="Sscreenshot-applet.jar,jmf.jar" name="main"  width="120" height="60" mayscript>
    Attenzione: Devi abilitare le Applet!</applet>
    <input type="button" name="start" value="start" onclick="document.main.startFoto();" />
    <input type="button" name="stop" value="stop" onclick="document.main.stopFoto();" />

  3. #3
    ciao vedi se risolvi così:

    1) esegui il file "jmfregistry.exe" che trovi nella directory "/bin" dove hai installato JMF (C:\Programmi\JMF2.1.1e\bin)
    2) seleziona la checkbox relativa a "Allow file Writing from Applets"
    3) clicca su "commit"

    non so se è necessario riavviare, credo di no però nel caso riavvia e controlla se funziona.
    Administrator of NAMDesign.Net

  4. #4
    Utente di HTML.it
    Registrato dal
    Mar 2008
    Messaggi
    101
    mi da sempre lo stesso errore..

  5. #5
    Su che sistema stai usando il tutto?
    Ci sono più account sul sistema?
    Stai utilizzando un account amministratore o "limitato"?

    Te lo chiedo perchè:
    1) sul mio pc con Windows XP ho 1 solo account (amministratore) ed è bastato fare quello che ti ho scritto nel post precedente e tutto ha cominciato a funzionare
    2) sul portatile (MacBook con installato Windows Vista) ho due account (con password) e non riesco a far funzionare la stessa applicazione (il mio codice per jmf) che sul PC va benissimo

    il tutto è un problema di permessi di qualche tipo perchè il file "jmfstudio" mi utilizza correttamente la webcam (iSight del MacBook) ed anche la mia applicazione se eseguo direttamente:
    codice:
    Player player = null;
    try {
       player = Manager.createRealizedPlayer(new MediaLocator("vfw://0"));
       player.start();
    } catch ( Exception e ) {
       System.out.println("Impossibile creare il player");
       System.exit(-1);
    }
    
    Component component = player.getVisualComponent();
    add(component);
    mentre se voglio ottenere l'elenco dei device sono per il momento riuscito a risolvere solo sul pc (col procedimento del altro post) ma sul portatile non ancora.
    Administrator of NAMDesign.Net

  6. #6
    Utente di HTML.it
    Registrato dal
    Mar 2008
    Messaggi
    101
    allora il pc su cui lo provo per ora è un portatile con window xp , dico per ora perche questa applet la dovrei distribuire su altri pc non gestiti da me. cmq anche questi pc sono con window xp.

    ma e possibile che devo installare su ogni postazione jmf?
    potrebbe bastare solo il jar di jmf?


    Cmq come si puo risolvere il problema?

  7. #7
    Utente di HTML.it
    Registrato dal
    Mar 2008
    Messaggi
    101
    mi potete aiutare???

  8. #8
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    ed eventualmente far codificare il video sul server stesso, in modo da installare JMF solo sul server ed essere sicuri che funzionerà su tutte le macchine (senza dover creare un'installazione ad-hoc di JMF per ciascuna di esse)? Certo hai il "grosso" svantaggio dell'alto traffico generato da/verso il server... ma almeno sei sicuro che funzioni bene indipendentemente da chi ci si attacca.
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  9. #9
    Utente di HTML.it
    Registrato dal
    Mar 2008
    Messaggi
    101
    OK, l'idea è ottima ma come si potrebbe fare ??

    Le foto che crea le dovrei mettere in memoria e non piu una cartella fisica , come si puo fare questo?

    Mi dovrei zippare tutte le foto poste in memoria e inviarle al server anche questo come si puo fare?

    Poi il server come capisce che l'applet gli ha inviato uno file zippato da lavorare?


    grazie.

  10. #10
    Utente di HTML.it
    Registrato dal
    Mar 2008
    Messaggi
    101
    qualcuno mi puo aiutare!!!!!!1

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.