21.04.2014 Views

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CURSO ANDROID<br />

60<br />

fileName = Environment.getExternalStorageDirectory() + “/test.mp4”;<br />

También para el SurfaceView don<strong>de</strong> se reproducirá el ví<strong>de</strong>o:<br />

SurfaceView surface = (SurfaceView)findViewById(R.id.surface);<br />

SurfaceHol<strong>de</strong>r hol<strong>de</strong>r = surface.getHol<strong>de</strong>r();<br />

hol<strong>de</strong>r.addCallback(this);<br />

hol<strong>de</strong>r.setType(SurfaceHol<strong>de</strong>r.SURFACE_TYPE_PUSH_BUFFERS);<br />

Definimos los botones sobre los que vamos a trabajar en su evento <strong>de</strong> click:<br />

final Button btnRec = (Button)findViewById(R.id.btnRec);<br />

final Button btnStop = (Button)findViewById(R.id.btnStop);<br />

final Button btnPlay = (Button)findViewById(R.id.btnPlay);<br />

Botón <strong>de</strong> grabación: al iniciar <strong>de</strong>shabilitamos los botones <strong>de</strong> grabar y reproducir luego habilitamos el<br />

<strong>de</strong> <strong>de</strong>tener. Llamamos el método que configura el MediaRecor<strong>de</strong>r y le <strong>de</strong>cimos el archivo <strong>de</strong> salida. Una<br />

vez configurado todo llamamos al método prepare que <strong>de</strong>ja todo listo para iniciar la grabación e iniciamos<br />

la grabación y actualizamos el estatus <strong>de</strong> la variable recording.<br />

btnRec.setOnClickListener(new OnClickListener() {<br />

@Overri<strong>de</strong><br />

public void onClick(View v) {<br />

btnRec.setEnabled(false);<br />

btnStop.setEnabled(true);<br />

btnPlay.setEnabled(false);<br />

prepareRecor<strong>de</strong>r();<br />

mediaRecor<strong>de</strong>r.setOutputFile(fileName);<br />

try {<br />

mediaRecor<strong>de</strong>r.prepare();<br />

} catch (IllegalStateException e) {<br />

} catch (IOException e) {<br />

} mediaRecor<strong>de</strong>r.start();<br />

recording = true;<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!