Java ME Suche aufgenommene Datei

Enigma228

Bekanntes Mitglied
Ich habe ein kleines Programm geschrieben, mit dem ich hoffe aufnehmen zu können..
Er führt das Programm auch einwandfrei aus, aber wenn die gespeicherte Datei test.wav suche, existiert sie nicht!!
Wo liegt mein Fehler??
Für Verbesserungen/Korrekturen zu meinem Programm würde ich mich sehr freuen!!
Man kann aus Fehlern ja nur lernen..


Java:
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class FirstCapture extends MIDlet implements CommandListener {

	private Command b_exit, b_record, b_stop;
	private Form form;
	private Display display;
	private Player capturePlayer, playbackPlayer;
	private byte[] recordedAudioArray = null;
	private RecordControl rc;
	private ByteArrayOutputStream output = new ByteArrayOutputStream();
	private Thread t;
	
	public FirstCapture() {
		display = Display.getDisplay(this);
		b_exit = new Command("Exit", Command.EXIT, 0);
		b_record = new Command("Record", Command.SCREEN, 1);
		b_stop = new Command("Stop", Command.SCREEN, 2);
		form = new Form("FirstCapture");
		form.addCommand(b_exit);
		form.addCommand(b_record);
		form.addCommand(b_stop);
		form.setCommandListener(this);
		display.setCurrent(form);
	}

	public void commandAction(Command c, Displayable d) {
		if(c==b_exit){
			try {
				this.destroyApp(false);
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}
		}
		if(c==b_record){
			t  = new Thread(){
				public void run(){
					try {
						form.append("Player erstellen");
						capturePlayer = Manager.createPlayer("capture://audio?encoding=pcm");
						form.append("Player.realize()");
						capturePlayer.realize();
						form.append("RecordControl eerstellen");
						rc = (RecordControl)capturePlayer.getControl("RecordControl");
						form.append("RecordLocation festgelegt");
						rc.setRecordLocation("file:///test.wav");
						form.append("RecordControl.setRecordStream()");
						rc.setRecordStream(output);
						form.append("RecordControl.startRecord()");
						rc.startRecord();
						form.append("Player starten");
						capturePlayer.start();
						form.append("Player gestartet");
					} catch (IOException e) {
						form.append(e.getMessage());
					} catch (MediaException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			t.start();
		}
		if(c==b_stop){
			try{
				form.append("RecordControl.stopRecord()");
				rc.stopRecord();
				form.append("RecordControl.stopRecord()");
				rc.commit();
				form.append("Player stoppen");
				capturePlayer.stop();
				form.append("Player schliessen");
				capturePlayer.close();
				recordedAudioArray = output.toByteArray();
				form.append("Thread unterbrechen");
				t.interrupt();
				t = null;
			}catch (Exception e) {
				// TODO: handle exception
			}
		}
		
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		notifyDestroyed();

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		
	}

}
 

AmunRa

Gesperrter Benutzer
ICh kann nur Raten, bist du dir sicher, dass der Pfadso stimmt?

Code:
file:///test.wav
auf welchem Mobiltelefon willst du das Test?
 

Enigma228

Bekanntes Mitglied
Hallo danke für die Antwort!!
Ich verwende ein Sony Ericsson W995 und habe schon rausgefunden das der Pfad falsch ist..

ich habe daraufhin mein Programm ein wenig modifiziert..

die Datei lässt sich leider aber nicht abspielen!!
er gibt mir die Datei mit 0 Bytes an.. als wenn er nichts reingeschrieben bekommt..
daraufhin habe ich ein wenig probiert.. siehe die ganzen form.append's.
er kommt bei den Form.append's lediglich bis RecordControl.setRecordStream().. danach nichts mehr.. das heisst er setzt den Recordstream garnicht!!
Hast du ne Idee woran das liegt?
ich habe alle Abfragen bezüglich schreib und Leserecht mit ja bestätigt.


Code:
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.microedition.io.Connection;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;

import com.sun.midp.io.j2me.storage.File;


public class FirstCapture extends MIDlet implements CommandListener {

	private Command b_exit, b_record, b_stop;
	private Form form;
	private Display display;
	private Player capturePlayer, playbackPlayer;
	private byte[] recordedAudioArray = null;
	private RecordStore rs;
	private RecordControl rc;
	private ByteArrayOutputStream output = new ByteArrayOutputStream();
	private Thread t;
	private boolean breaker=true;
	
	public FirstCapture() {
		display = Display.getDisplay(this);
		b_exit = new Command("Exit", Command.EXIT, 0);
		b_record = new Command("Record", Command.SCREEN, 1);
		b_stop = new Command("Stop", Command.SCREEN, 2);
		try {
			rs = RecordStore.openRecordStore("MyAudioCaptures", true);
		} catch (RecordStoreFullException e) {
			e.printStackTrace();
		} catch (RecordStoreNotFoundException e) {
			e.printStackTrace();
		} catch (RecordStoreException e) {
			e.printStackTrace();
		}
		form = new Form("FirstCapture");
		form.addCommand(b_exit);
		form.addCommand(b_record);
		//form.addCommand(b_stop);
		form.setCommandListener(this);
		display.setCurrent(form);
	}

	public void commandAction(Command c, Displayable d) {
		if(c==b_exit){
			try {
				this.destroyApp(false);
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}
		}
		if(c==b_record){
			form.deleteAll();
			form.removeCommand(b_exit);
			form.removeCommand(b_record);
			form.addCommand(b_stop);
			
			breaker=true;
			t  = new Thread(){
				public void run(){
					try {
						form.append("Player erstellen");
						capturePlayer = Manager.createPlayer("capture://audio?encoding=pcm");
						form.append("Player.realize()");
						capturePlayer.realize();
						form.append("RecordControl eerstellen");
						rc = (RecordControl)capturePlayer.getControl("RecordControl");
						form.append("RecordLocation festgelegt");
						FileConnection fc = (FileConnection)Connector.open("file:///e:/test.wav",Connector.READ_WRITE);
						if(!fc.exists()){
							fc.create();
							fc.setWritable(true);
						}
						fc.close();
						rc.setRecordLocation("file:///e:/test.wav");
						form.append("RecordControl.setRecordStream()");
						rc.setRecordStream(output);
						form.append("RecordControl.startRecord()");
						rc.startRecord();
						form.append("Player starten");
						capturePlayer.start();
						form.append("Player gestartet");
						while(breaker){};
						form.append("RecordControl.stopRecord()");
						rc.stopRecord();
						form.append("RecordControl.stopRecord()");
						rc.commit();
						form.append("Player stoppen");
						capturePlayer.stop();
						form.append("Player schliessen");
						capturePlayer.close();
						recordedAudioArray = output.toByteArray();
						form.append("Datenstrom: "+recordedAudioArray.length);
						FileConnection fc2 = (FileConnection)Connector.open("file:///e:/test.wav",Connector.READ_WRITE);
						
						OutputStream bous = fc.openOutputStream();
						bous.write(recordedAudioArray);
						bous.close();
						fc2.close();
						//rs.addRecord(recordedAudioArray, 0, recordedAudioArray.length);
						
					} catch (IOException e) {
						form.append(e.getMessage());
					} catch (MediaException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			};
			t.start();
		}
		if(c==b_stop){
			breaker=false;
			form.removeCommand(b_stop);
			form.addCommand(b_record);
			form.addCommand(b_exit);
		}
		
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		notifyDestroyed();

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		
	}

}
 

Enigma228

Bekanntes Mitglied
Fehler gefunden.. er mag einfach nicht wenn man ihm eine RecordLocation und einen Stream verpasst..
weiterhin habe ich im Bereich, in dem in die Datei geschrieben wurde, eine falsche FileConnection benutzt..

So jetzt habe ich eine Aufnahme, aber..
Der Text ist "Hallo das ist eine Aufnahme"
es klingt als wenn das ganze sehr stark komprimiert ist

ich habe es mal hinten rangehängt!!
Hinweis es erfolgte keine Komprimierung mit Winzip nur eine Speicherung!!

Was läuft da noch verkehrt?

Java:
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.microedition.io.Connection;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;

import com.sun.midp.io.j2me.storage.File;


public class FirstCapture extends MIDlet implements CommandListener {

	private Command b_exit, b_record, b_stop;
	private Form form;
	private Display display;
	private Player capturePlayer, playbackPlayer;
	private byte[] recordedAudioArray = null;
	private RecordStore rs;
	private RecordControl rc;
	private ByteArrayOutputStream output = new ByteArrayOutputStream();
	private Thread t;
	private boolean breaker=true;
	
	public FirstCapture() {
		display = Display.getDisplay(this);
		b_exit = new Command("Exit", Command.EXIT, 0);
		b_record = new Command("Record", Command.SCREEN, 1);
		b_stop = new Command("Stop", Command.SCREEN, 2);
		try {
			rs = RecordStore.openRecordStore("MyAudioCaptures", true);
		} catch (RecordStoreFullException e) {
			e.printStackTrace();
		} catch (RecordStoreNotFoundException e) {
			e.printStackTrace();
		} catch (RecordStoreException e) {
			e.printStackTrace();
		}
		form = new Form("FirstCapture");
		form.addCommand(b_exit);
		form.addCommand(b_record);
		//form.addCommand(b_stop);
		form.setCommandListener(this);
		display.setCurrent(form);
	}

	public void commandAction(Command c, Displayable d) {
		if(c==b_exit){
			try {
				this.destroyApp(false);
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}
		}
		if(c==b_record){
			form.deleteAll();
			form.removeCommand(b_exit);
			form.removeCommand(b_record);
			form.addCommand(b_stop);
			
			breaker=true;
			t  = new Thread(){
				public void run(){
					try {
						form.append("Player erstellen");
						capturePlayer = Manager.createPlayer("capture://audio?encoding=pcm");
						form.append("Player.realize()");
						capturePlayer.realize();
						form.append("RecordControl eerstellen");
						rc = (RecordControl)capturePlayer.getControl("RecordControl");
						form.append("RecordLocation festgelegt");
						FileConnection fc = (FileConnection)Connector.open("file:///e:/test.wav",Connector.READ_WRITE);
						if(!fc.exists()){
							fc.create();
							fc.setWritable(true);
						}
						fc.close();
						//rc.setRecordLocation("file:///e:/test.wav");
						form.append("RecordControl.setRecordStream()");
						rc.setRecordStream(output);
						form.append("RecordControl.startRecord()");
						rc.startRecord();
						form.append("Player starten");
						capturePlayer.start();
						form.append("Player gestartet");
						while(breaker){};
						form.append("RecordControl.stopRecord()");
						rc.stopRecord();
						form.append("RecordControl.stopRecord()");
						rc.commit();
						form.append("Player stoppen");
						capturePlayer.stop();
						form.append("Player schliessen");
						capturePlayer.close();
						recordedAudioArray = output.toByteArray();
						form.append("Datenstrom: "+recordedAudioArray.length);
						FileConnection fc2 = (FileConnection)Connector.open("file:///e:/test.wav",Connector.READ_WRITE);
						fc2.setWritable(true);
						form.append("fc2 eingerichtet");
						OutputStream bous = fc2.openOutputStream();
						form.append("Outputstream auf Datei geholt");
						bous.write(recordedAudioArray);
						form.append("ByteArray wurde geschrieben");
						bous.close();
						fc2.close();
						//rs.addRecord(recordedAudioArray, 0, recordedAudioArray.length);
						
					} catch (Exception e) {
						form.append(e.getMessage());
					}
				}
			};
			t.start();
		}
		if(c==b_stop){
			breaker=false;
			form.removeCommand(b_stop);
			form.addCommand(b_record);
			form.addCommand(b_exit);
		}
		
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		notifyDestroyed();

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		
	}

}
 

Anhänge

  • test.zip
    36,4 KB · Aufrufe: 0

Enigma228

Bekanntes Mitglied
ich habe ein wenig mit Codecs rumexperimentiert..
Statt einer wav-Datei erstelle ich jetzt eine amr-Datei (frisst sogar weniger Speicher!!)
Java:
FileConnection fc = (FileConnection)Connector.open("file:///e:/test.amr",Connector.READ_WRITE);
und verwende als Codec
Java:
capturePlayer = Manager.createPlayer("capture://audio?encoding=amr");

und eine amr-Datei kann man ganz leicht FormatFactory in zB. mp3 umwandeln..

Danke!!
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
AllBlack Suche Programmierer in Java und Kotlin mit dem ich mich Selbstständig machen kann Android & Cross-Platform Mobile Apps 23
AllBlack Auf der Suche nach einem App-Entwickler Android & Cross-Platform Mobile Apps 1
M Barrierefreie Appentwicklung für Android - Suche Codebeispiele Android & Cross-Platform Mobile Apps 8
J Android Suche in einer ListView Android & Cross-Platform Mobile Apps 3
M Suche eine Webseite mit dem aktuelle Datum in XML Android & Cross-Platform Mobile Apps 18
M Android Suche Activity/View Namen Android & Cross-Platform Mobile Apps 1
M Suche Name von View Komponente Android & Cross-Platform Mobile Apps 10
K suche nach der richtigen dokumentationh Android & Cross-Platform Mobile Apps 2
F Suche ME Beschreibung Android & Cross-Platform Mobile Apps 2
B Suche Klassenbeschreibungen und Bluetoothfunktionen. Android & Cross-Platform Mobile Apps 3
F Suche Javaspiele - Programmierer! Android & Cross-Platform Mobile Apps 5
T [Suche:] DECT-Mobiltelefon mit Javaunterstützung Android & Cross-Platform Mobile Apps 2
I Foto mit einer bestimmten Auflösung aufnehmen und als Datei ablegen. Android & Cross-Platform Mobile Apps 5
I Android CameraApp, eingebaute App nutzen und Ergebniss als Datei speichern Android & Cross-Platform Mobile Apps 0
R Android Audio-Datei fliessend vorspulen Android & Cross-Platform Mobile Apps 9
J Android Zugriff auf eine Datei, diese von einer anderen App erstellt wurde? Android & Cross-Platform Mobile Apps 11
T Screenshot speichern ohne alte Datei überschreiben Android & Cross-Platform Mobile Apps 3
R Audio-Datei abspielen Android & Cross-Platform Mobile Apps 3
L Android content URI Datei einlesen Android & Cross-Platform Mobile Apps 9
S Android Datei aus dem Netz einlesen Android & Cross-Platform Mobile Apps 6
V Android Wird mein Vorhaben funktionieren? (Apk Datei decompilieren, bearbeiten, compilieren) Android & Cross-Platform Mobile Apps 2
L Android Datei Übertragung im Netzwerk Android & Cross-Platform Mobile Apps 8
S Termin aus *.txt Datei in Google Kalender eintragen? Android & Cross-Platform Mobile Apps 1
S *.APK Datei automatisch installieren? Android & Cross-Platform Mobile Apps 4
JavaWolf165 Android Fehler beim Speichern/Downloaden einer Datei Android & Cross-Platform Mobile Apps 2
B Android XML Datei editieren --> Permission denied Android & Cross-Platform Mobile Apps 2
M Android Speichern einer .txt Datei im InternalStorage Android & Cross-Platform Mobile Apps 2
B Android Absolute kml-Datei erzeugen Android & Cross-Platform Mobile Apps 2
B Fragen zum Speichern einer Datei auf dem Gerät? Android & Cross-Platform Mobile Apps 7
S Listview Einträge aus "xml" Datei Android & Cross-Platform Mobile Apps 1
G Datei erstellen Android & Cross-Platform Mobile Apps 10
L Android Apache POI: Datei speichern geht nicht Android & Cross-Platform Mobile Apps 1
A Android Datei erstellen/schreiben/auslesen Android & Cross-Platform Mobile Apps 1
K Android Erstellt Ordner statt Datei. Android & Cross-Platform Mobile Apps 3
M Datei verschicken per byteArray? Android & Cross-Platform Mobile Apps 1
L Android Datei erstellen, Daten einspeichern und auslesen Android & Cross-Platform Mobile Apps 2
B Datei downloaden über DialogBox? Android & Cross-Platform Mobile Apps 4
G Datei im Ordner speichern Android & Cross-Platform Mobile Apps 2
G Datei erzeugen, per E-Mail senden Android & Cross-Platform Mobile Apps 5
D Android WAV-Datei abspielen / Klangfolge(Endlos) Android & Cross-Platform Mobile Apps 4
A Android Eine Datei in Android löschen, aber wie ? Android & Cross-Platform Mobile Apps 24
D gpx-Datei von Smartphone auf Server uploaden Android & Cross-Platform Mobile Apps 4
U [Android] Eine Datei aus Jar-Archiv laden Android & Cross-Platform Mobile Apps 4
T Android Ergebnis eines XML+XSLT "transform" in eine HTML - Datei schreiben (Android) Android & Cross-Platform Mobile Apps 2
K mp3 datei in j2me abspielen Android & Cross-Platform Mobile Apps 16
M Text in txt-Datei schreiben und nach ABC sortieren? Android & Cross-Platform Mobile Apps 2
R String wie WAV Datei nutzen Android & Cross-Platform Mobile Apps 4
A jad-Datei to N95 Android & Cross-Platform Mobile Apps 18
C 2 kleine Probleme (Datei lesen, String durchsuchen) Android & Cross-Platform Mobile Apps 16
L SecurityException beim lesen/schreiben eine Datei Android & Cross-Platform Mobile Apps 7
G WAV datei abspielen aber wohin kopieren ? Android & Cross-Platform Mobile Apps 2
S Variable Anzahl von Bytes aus einer Datei lesen Android & Cross-Platform Mobile Apps 2

Ähnliche Java Themen

Neue Themen


Oben