Issue #171 terminado

parent 6a4b7745
...@@ -51,6 +51,7 @@ import com.yottacode.tools.GUITools; ...@@ -51,6 +51,7 @@ import com.yottacode.tools.GUITools;
import org.json.JSONException; import org.json.JSONException;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
...@@ -119,7 +120,7 @@ public class EditPictoActivity extends Activity { ...@@ -119,7 +120,7 @@ public class EditPictoActivity extends Activity {
private String dirAudioPath = null; private String dirAudioPath = null;
private MediaRecorder mRecorder = null; private MediaRecorder mRecorder = null;
private MediaPlayer mPlayer; private MediaPlayer mPlayer = null;
BotonCircular botonGrabar; BotonCircular botonGrabar;
BotonCircular botonReproducir; BotonCircular botonReproducir;
...@@ -178,14 +179,13 @@ public class EditPictoActivity extends Activity { ...@@ -178,14 +179,13 @@ public class EditPictoActivity extends Activity {
botonReproducir.setEnabled(tiempoGrabado > 1 ? true : false); botonReproducir.setEnabled(tiempoGrabado > 1 ? true : false);
layoutPreview.setVisibility(tiempoGrabado > 1 ? View.VISIBLE : View.GONE); layoutPreview.setVisibility(tiempoGrabado > 1 ? View.VISIBLE : View.GONE);
layoutGrabacion.setVisibility(tiempoGrabado > 1 ? View.GONE : View.VISIBLE); layoutGrabacion.setVisibility(tiempoGrabado > 1 ? View.GONE : View.VISIBLE);
textoTTotal.setText(tiempoGrabado == 10 ? "00:00 | 00:" + tiempoGrabado : "00:00 | 00:0" + tiempoGrabado );
tiempoTotal = tiempoGrabado-1; tiempoTotal = tiempoGrabado-1;
textoTTotal.setText(tiempoTotal == 10 ? "00:00 | 00:" + tiempoTotal : "00:00 | 00:0" + tiempoTotal );
barraReproducir.setMax(tiempoTotal); barraReproducir.setMax(tiempoTotal);
botonGrabar.PhidePressedRing(); botonGrabar.PhidePressedRing();
if(tiempoGrabado>1) hayGrabacion = true ; if(tiempoGrabado > 1) hayGrabacion = true ;
else hayGrabacion = false; else hayGrabacion = false;
reiniciarGrabacion(); reiniciarGrabacion();
} }
} }
...@@ -217,7 +217,7 @@ public class EditPictoActivity extends Activity { ...@@ -217,7 +217,7 @@ public class EditPictoActivity extends Activity {
protected void onCancelled(){ protected void onCancelled(){
stopPlaying(); 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(); reiniciarReproducción();
} }
} }
...@@ -343,24 +343,20 @@ public class EditPictoActivity extends Activity { ...@@ -343,24 +343,20 @@ public class EditPictoActivity extends Activity {
//Obtener el picto a editar //Obtener el picto a editar
if(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)); p = PCBcontext.getVocabulary().get_picto(getIntent().getExtras().getInt(Picto.JSON_ATTTRS.CATEGORY),getIntent().getExtras().getInt(PictoMenu.ID_PICTO_IMAGE));
legend.setText(p.get_translation()); legend.setText(p.get_translation());
supAsociado.setText(p.get_user_avatar()==null ? NO_SUP_TEXT : p.get_user_avatar()); supAsociado.setText(p.get_user_avatar()==null ? NO_SUP_TEXT : p.get_user_avatar());
//Si el picto viene con sonido //Si el picto viene con sonido
if(p.getUriSound() != null){ if(p.get_audioFile() != null){
borrado = false; 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; hayGrabacion = true;
//tiempoTotal = mPlayer.getDuration(); Log.i(DEBUG_MESSAGE,"Picto CON sonido asociado");
layoutGrabacion.setVisibility(View.GONE); layoutGrabacion.setVisibility(View.GONE);
layoutPreview.setVisibility(View.VISIBLE);
botonReproducir.setEnabled(true);
assignFileToPlayer(p.get_audioFile());
}else{ }else{
Log.i(DEBUG_MESSAGE,"Picto SIN sonido asociado"); Log.i(DEBUG_MESSAGE,"Picto SIN sonido asociado");
layoutPreview.setVisibility(View.INVISIBLE); layoutPreview.setVisibility(View.INVISIBLE);
...@@ -447,24 +443,28 @@ public class EditPictoActivity extends Activity { ...@@ -447,24 +443,28 @@ public class EditPictoActivity extends Activity {
} }
if(hayGrabacion) { //Si ha grabado algo -> Ir a renombrarlo if(hayGrabacion) { //Si ha grabado algo -> Ir a renombrarlo
Log.i(DEBUG_MESSAGE,"Ha grabado pasa a comprobar");
File file = new File(previewAudioPath); File file = new File(previewAudioPath);
if (file.exists()) { if (file.exists()) {
Log.i(DEBUG_MESSAGE,"fichero test.mp3 y existia");
File from = new File(previewAudioPath); File from = new File(previewAudioPath);
File to = new File(editar ? dirAudioPath + File.separator + legend.getText().toString() + "_" + id_pic + "_audio.mp3" : 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"); dirAudioPath + File.separator + legend.getText().toString() + "_new_" + pathNumber + "_audio.mp3");
if (from.exists()){ if (from.exists()){
from.renameTo(to); from.renameTo(to);
audioPath = to.getPath().toString(); 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 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.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, 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); Log.e(LOG_TAG, "PATH SOUND:"+audioPath);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, legend.getText().toString()); //Mandar expresion nueva 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)); intent.putExtra(Picto.JSON_ATTTRS.CATEGORY, getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1));
...@@ -495,26 +495,25 @@ public class EditPictoActivity extends Activity { ...@@ -495,26 +495,25 @@ public class EditPictoActivity extends Activity {
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){ switch(event.getAction()){
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
recordSoundOn.play(MediaActionSound.SHUTTER_CLICK); recordSoundOn.play(MediaActionSound.START_VIDEO_RECORDING);
tareaGrabacion = (RecordTask) new RecordTask().execute(tiempoGrabado);
gifRecord.setBackgroundResource(R.drawable.record_animation);
try { //Para que no capture el sonido del sistema try { //Para que no capture el sonido del sistema
sleep(600); sleep(500);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
gifRecord.setBackgroundResource(R.drawable.record_animation);
tareaGrabacion = (RecordTask) new RecordTask().execute(tiempoGrabado);
startRecording(); startRecording();
Log.i(DEBUG_MESSAGE,"Grabando.."); Log.i(DEBUG_MESSAGE,"Grabando..");
return true; return true;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
gifRecord.setBackgroundResource(R.color.white);
tareaGrabacion.cancel(true); tareaGrabacion.cancel(true);
//mPlayer.setDataSource(previewAudioPath); gifRecord.setBackgroundResource(R.color.white);
assignFileToPlayer(/*mPlayer,*/previewAudioPath); assignFileToPlayer(new File(previewAudioPath));
recordSoundOff.play(MediaActionSound.FOCUS_COMPLETE); recordSoundOff.play(MediaActionSound.FOCUS_COMPLETE);
return true; return true;
} }
return false; return false;
...@@ -524,6 +523,7 @@ public class EditPictoActivity extends Activity { ...@@ -524,6 +523,7 @@ public class EditPictoActivity extends Activity {
botonReproducir.setOnClickListener(new View.OnClickListener() { botonReproducir.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Log.i(DEBUG_MESSAGE,"Click");
if(reproduciendo){ if(reproduciendo){
tareaReproduccion.cancel(true); tareaReproduccion.cancel(true);
reproduciendo = false; reproduciendo = false;
...@@ -531,9 +531,9 @@ public class EditPictoActivity extends Activity { ...@@ -531,9 +531,9 @@ public class EditPictoActivity extends Activity {
botonReproducir.setImageResource(android.R.drawable.ic_media_play); botonReproducir.setImageResource(android.R.drawable.ic_media_play);
}else{ }else{
reproduciendo = true; reproduciendo = true;
startPlaying();
Log.i(DEBUG_MESSAGE,"Reproducir"); 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); botonReproducir.setImageResource(android.R.drawable.ic_media_pause);
} }
} }
...@@ -544,14 +544,14 @@ public class EditPictoActivity extends Activity { ...@@ -544,14 +544,14 @@ public class EditPictoActivity extends Activity {
public void onClick(View v) { public void onClick(View v) {
borrado = true; borrado = true;
if(hayGrabacion){ if(hayGrabacion){
mPlayer.release(); stopPlaying();
if(editar){ /*if(editar){
if(p.getUriSound() != null) { if(p.getUriSound() != null) {
Log.i(DEBUG_MESSAGE,"Eliminado->"+p.getUriSound()); Log.i(DEBUG_MESSAGE,"Eliminado->"+p.getUriSound());
p.setUriSound(null); p.setUriSound(null);
} }
} }*/
Log.i(DEBUG_MESSAGE,"Eliminado->"+previewAudioPath); //Log.i(DEBUG_MESSAGE,"Eliminado->"+previewAudioPath);
layoutGrabacion.setVisibility(View.VISIBLE); layoutGrabacion.setVisibility(View.VISIBLE);
layoutPreview.setVisibility(View.GONE); layoutPreview.setVisibility(View.GONE);
hayGrabacion = false; hayGrabacion = false;
...@@ -613,39 +613,34 @@ public class EditPictoActivity extends Activity { ...@@ -613,39 +613,34 @@ public class EditPictoActivity extends Activity {
} }
private void assignFileToPlayer(String pathReproducir){ private void assignFileToPlayer(File audio){
mPlayer = new MediaPlayer(); mPlayer = new MediaPlayer();
try { try {
mPlayer.setDataSource(pathReproducir); mPlayer.setDataSource(new FileInputStream(audio).getFD());
} catch (IOException e) {
e.printStackTrace();
}
}
private void startPlaying(/*MediaPlayer m*/) {
//m = new MediaPlayer();
try {
//mPlayer.setDataSource(pathReproducir);
mPlayer.prepare(); 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) { } catch (IOException e) {
Log.e(DEBUG_MESSAGE, "prepare() failed"); e.printStackTrace();
} catch (IllegalStateException e){ } catch (IllegalStateException e){
Log.e(DEBUG_MESSAGE, "Illegal state exception on prepare()"); Log.e(DEBUG_MESSAGE, "Illegal state exception on prepare()");
} }
} }
private void pausePlay(MediaPlayer m){ private void startPlaying() {
if(m.isPlaying()){ try {
m.pause(); mPlayer.start();
}else{ }catch (IllegalStateException e){
m.start(); Log.e(DEBUG_MESSAGE, "Illegal state exception on start()");
} }
} }
private void stopPlaying(/*MediaPlayer m*/) { private void stopPlaying() {
mPlayer.stop();
mPlayer.reset(); mPlayer.reset();
//mPlayer = null; mPlayer.release();
mPlayer = null;
} }
private void startRecording() { 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