Issue #171 terminado

parent 6a4b7745
......@@ -51,6 +51,7 @@ import com.yottacode.tools.GUITools;
import org.json.JSONException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
......@@ -119,7 +120,7 @@ public class EditPictoActivity extends Activity {
private String dirAudioPath = null;
private MediaRecorder mRecorder = null;
private MediaPlayer mPlayer;
private MediaPlayer mPlayer = null;
BotonCircular botonGrabar;
BotonCircular botonReproducir;
......@@ -178,14 +179,13 @@ public class EditPictoActivity extends Activity {
botonReproducir.setEnabled(tiempoGrabado > 1 ? true : false);
layoutPreview.setVisibility(tiempoGrabado > 1 ? View.VISIBLE : View.GONE);
layoutGrabacion.setVisibility(tiempoGrabado > 1 ? View.GONE : View.VISIBLE);
textoTTotal.setText(tiempoGrabado == 10 ? "00:00 | 00:" + tiempoGrabado : "00:00 | 00:0" + tiempoGrabado );
tiempoTotal = tiempoGrabado-1;
textoTTotal.setText(tiempoTotal == 10 ? "00:00 | 00:" + tiempoTotal : "00:00 | 00:0" + tiempoTotal );
barraReproducir.setMax(tiempoTotal);
botonGrabar.PhidePressedRing();
if(tiempoGrabado>1) hayGrabacion = true ;
if(tiempoGrabado > 1) hayGrabacion = true ;
else hayGrabacion = false;
reiniciarGrabacion();
}
}
......@@ -217,7 +217,7 @@ public class EditPictoActivity extends Activity {
protected void onCancelled(){
stopPlaying();
assignFileToPlayer(editar ? (p.getUriSound() != null ? p.get_audioPath() : previewAudioPath) : null);
assignFileToPlayer(editar ? ((!borrado && p.get_audioFile()!=null) ? p.get_audioFile() : new File(previewAudioPath)) : null);
reiniciarReproducción();
}
}
......@@ -343,24 +343,20 @@ public class EditPictoActivity extends Activity {
//Obtener el picto a editar
if(editar){
Log.i(DEBUG_MESSAGE,"EDITAR");
p = PCBcontext.getVocabulary().get_picto(getIntent().getExtras().getInt(Picto.JSON_ATTTRS.CATEGORY),getIntent().getExtras().getInt(PictoMenu.ID_PICTO_IMAGE));
legend.setText(p.get_translation());
supAsociado.setText(p.get_user_avatar()==null ? NO_SUP_TEXT : p.get_user_avatar());
//Si el picto viene con sonido
if(p.getUriSound() != null){
if(p.get_audioFile() != null){
borrado = false;
Log.i(DEBUG_MESSAGE,"Ruta: "+p.getUriSound() +"---Ruta2: "+p.get_audioPath());
Log.i(DEBUG_MESSAGE,"Picto CON sonido asociado");
layoutPreview.setVisibility(View.VISIBLE);
File file = new File(p.get_audioPath());
assignFileToPlayer(file.getPath());
tiempoTotal = mPlayer.getDuration();
hayGrabacion = true;
//tiempoTotal = mPlayer.getDuration();
Log.i(DEBUG_MESSAGE,"Picto CON sonido asociado");
layoutGrabacion.setVisibility(View.GONE);
layoutPreview.setVisibility(View.VISIBLE);
botonReproducir.setEnabled(true);
assignFileToPlayer(p.get_audioFile());
}else{
Log.i(DEBUG_MESSAGE,"Picto SIN sonido asociado");
layoutPreview.setVisibility(View.INVISIBLE);
......@@ -447,24 +443,28 @@ public class EditPictoActivity extends Activity {
}
if(hayGrabacion) { //Si ha grabado algo -> Ir a renombrarlo
Log.i(DEBUG_MESSAGE,"Ha grabado pasa a comprobar");
File file = new File(previewAudioPath);
if (file.exists()) {
Log.i(DEBUG_MESSAGE,"fichero test.mp3 y existia");
File from = new File(previewAudioPath);
File to = new File(editar ? dirAudioPath + File.separator + legend.getText().toString() + "_" + id_pic + "_audio.mp3" :
dirAudioPath + File.separator + legend.getText().toString() + "_new_" + pathNumber + "_audio.mp3");
if (from.exists()){
from.renameTo(to);
audioPath = to.getPath().toString();
Log.i(DEBUG_MESSAGE,"Path renombrado "+audioPath);
}
}
}
Log.i(DEBUG_MESSAGE,"Picto: "+p.get_translation()+"--sonido: "+p.get_audioPath()+"-->"+p.getUriSound());
Intent intent = getIntent(); //Mandar a pictogram activity el path y el texto de la imagen
intent.putExtra(PictoMenu.IS_EDIT, editar); //Para saber despues si estas editando o añadiendo nuevo y coger los datos de intent o de data en OnActivityResult
intent.putExtra(PictoMenu.PATH, filepath); //Mandar Path imagen
intent.putExtra(PictoMenu.PATH_SOUND,borrado ? audioPath : p.get_audioPath()); //Mandar el path del audio
intent.putExtra(PictoMenu.PATH_SOUND,editar ? ((!borrado && p.getUriSound()!= null) ? p.get_audioPath() : audioPath) : audioPath); //Mandar el path del audio
Log.i(DEBUG_MESSAGE,"Manda esto: "+ (editar ? ((!borrado && p.getUriSound()!= null) ? "p.get_audioPath()" : "borrado+audioPath" ) : "audioPath"));
Log.e(LOG_TAG, "PATH SOUND:"+audioPath);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, legend.getText().toString()); //Mandar expresion nueva
intent.putExtra(Picto.JSON_ATTTRS.CATEGORY, getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1));
......@@ -495,26 +495,25 @@ public class EditPictoActivity extends Activity {
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
recordSoundOn.play(MediaActionSound.SHUTTER_CLICK);
tareaGrabacion = (RecordTask) new RecordTask().execute(tiempoGrabado);
gifRecord.setBackgroundResource(R.drawable.record_animation);
recordSoundOn.play(MediaActionSound.START_VIDEO_RECORDING);
try { //Para que no capture el sonido del sistema
sleep(600);
sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
gifRecord.setBackgroundResource(R.drawable.record_animation);
tareaGrabacion = (RecordTask) new RecordTask().execute(tiempoGrabado);
startRecording();
Log.i(DEBUG_MESSAGE,"Grabando..");
return true;
case MotionEvent.ACTION_UP:
gifRecord.setBackgroundResource(R.color.white);
tareaGrabacion.cancel(true);
//mPlayer.setDataSource(previewAudioPath);
assignFileToPlayer(/*mPlayer,*/previewAudioPath);
gifRecord.setBackgroundResource(R.color.white);
assignFileToPlayer(new File(previewAudioPath));
recordSoundOff.play(MediaActionSound.FOCUS_COMPLETE);
return true;
}
return false;
......@@ -524,6 +523,7 @@ public class EditPictoActivity extends Activity {
botonReproducir.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(DEBUG_MESSAGE,"Click");
if(reproduciendo){
tareaReproduccion.cancel(true);
reproduciendo = false;
......@@ -531,9 +531,9 @@ public class EditPictoActivity extends Activity {
botonReproducir.setImageResource(android.R.drawable.ic_media_play);
}else{
reproduciendo = true;
startPlaying();
Log.i(DEBUG_MESSAGE,"Reproducir");
tareaReproduccion = (PlayTask) new PlayTask().execute(tiempoReproducir);
tareaReproduccion = (PlayTask) new PlayTask().execute(tiempoTotal);
startPlaying();
botonReproducir.setImageResource(android.R.drawable.ic_media_pause);
}
}
......@@ -544,14 +544,14 @@ public class EditPictoActivity extends Activity {
public void onClick(View v) {
borrado = true;
if(hayGrabacion){
mPlayer.release();
if(editar){
stopPlaying();
/*if(editar){
if(p.getUriSound() != null) {
Log.i(DEBUG_MESSAGE,"Eliminado->"+p.getUriSound());
p.setUriSound(null);
}
}
Log.i(DEBUG_MESSAGE,"Eliminado->"+previewAudioPath);
}*/
//Log.i(DEBUG_MESSAGE,"Eliminado->"+previewAudioPath);
layoutGrabacion.setVisibility(View.VISIBLE);
layoutPreview.setVisibility(View.GONE);
hayGrabacion = false;
......@@ -613,39 +613,34 @@ public class EditPictoActivity extends Activity {
}
private void assignFileToPlayer(String pathReproducir){
private void assignFileToPlayer(File audio){
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(pathReproducir);
} catch (IOException e) {
e.printStackTrace();
}
}
private void startPlaying(/*MediaPlayer m*/) {
//m = new MediaPlayer();
try {
//mPlayer.setDataSource(pathReproducir);
mPlayer.setDataSource(new FileInputStream(audio).getFD());
mPlayer.prepare();
mPlayer.start();
tiempoTotal = Math.round(mPlayer.getDuration()/1000);
textoTTotal.setText("00:00 | 00:"+(tiempoTotal == 10 ? tiempoTotal : "0" + tiempoTotal));
barraReproducir.setMax(tiempoTotal);
} catch (IOException e) {
Log.e(DEBUG_MESSAGE, "prepare() failed");
e.printStackTrace();
} catch (IllegalStateException e){
Log.e(DEBUG_MESSAGE, "Illegal state exception on prepare()");
}
}
private void pausePlay(MediaPlayer m){
if(m.isPlaying()){
m.pause();
}else{
m.start();
private void startPlaying() {
try {
mPlayer.start();
}catch (IllegalStateException e){
Log.e(DEBUG_MESSAGE, "Illegal state exception on start()");
}
}
private void stopPlaying(/*MediaPlayer m*/) {
private void stopPlaying() {
mPlayer.stop();
mPlayer.reset();
//mPlayer = null;
mPlayer.release();
mPlayer = null;
}
private void startRecording() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment