Multimedia en Android

Curso de Android

Contactar con el profesor

Cargar una imagen con la librería picasso

<manifest>
	<uses-permission android:name="android.permission.INTERNET" />
</manifest>
dependencies 
	implementation 'com.squareup.picasso:picasso:2.71828'
}
String imageUri = "https://i.imgur.com/tGbaZCY.jpg";
ImageView ivBasicImage = (ImageView) findViewById(R.id.ivBasicImage);
Picasso.get().load(imageUri).into(ivBasicImage);

Cargar un sonido

MediaPlayer mp = MediaPlayer.create(Audio.this, R.raw.hakunamatata);

Cargar un video

getWindow().setFormat(PixelFormat.TRANSLUCENT);
        VideoView videoHolder = new VideoView(this);
        //if you want the controls to appear
        videoHolder.setMediaController(new MediaController(this));
        Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
                + R.raw.leon);
        videoHolder.setVideoURI(video);
        setContentView(videoHolder);
        videoHolder.start();

Hacer streaming de un video

Habrá que dar permisos de conexión a internet en el:

AndroidManifest.xml<uses-permission android:name="android.permission.INTERNET"/>
String stringUrl = "https://pablomonteserin.com/curso/html5/ex/HakunaMatataItMeansNoWorries.mp3";
try {
	final MediaPlayer mediaPlayer = new MediaPlayer();
	mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
	mediaPlayer.setDataSource(stringUrl);
	mediaPlayer.prepareAsync();
	mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
		@Override
		public void onPrepared(MediaPlayer mp) {
			mediaPlayer.start();
		}
	});
} catch (Exception e) {
	e.printStackTrace();
}

Usar cámara de fotos

public void sacaFoto(View v){
	Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
	startActivityForResult(intent,0);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data){
	super.onActivityResult(requestCode, resultCode, data);
	Bitmap bm = (Bitmap) data.getExtras().get("data");
	iv.setImageBitmap(bm);
}
← SQLite
Navigation Drawer →

Aviso Legal | Política de privacidad