Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/01/2015, 07:39
micro20
 
Fecha de Ingreso: junio-2008
Mensajes: 33
Antigüedad: 15 años, 10 meses
Puntos: 2
VideoView URL con Autenticación

Buenos días Foreros,

vuelvo a necesitar ayuda con mi aplicación. Estoy leyendo un vídeo con VideoView desde una URL, lo cual me funciona correctamente, pero el problema viene cuando necesito hacer una autenticación ya que el servidor real está protegido con usuario y contraseña desde un .htaccess y .htpasswrd con autenticación Basic.

¿Podríais ayudarme por favor?

Muchas gracias por adelantado.

Dejo mi código para que reviséis como lo intento hacer:

Código Java:
Ver original
  1. public class VideoViewActivity extends Activity {
  2.  
  3.     ProgressDialog pDialog;
  4.     VideoView videoview;
  5.  
  6.     String VideoURL = "http://www.miservidor.com/video.3gp";
  7.  
  8.     @Override
  9.     protected void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);
  11.         // Get the layout from video_main.xml
  12.         setContentView(R.layout.activity_video_view);
  13.         // Find your VideoView in your video_main.xml layout
  14.         videoview = (VideoView) findViewById(R.id.VideoView);
  15.         // Execute StreamVideo AsyncTask
  16.  
  17.         // Create a progressbar
  18.         pDialog = new ProgressDialog(VideoViewActivity.this);
  19.         // Set progressbar title
  20.         pDialog.setTitle("Streaming Video");
  21.         // Set progressbar message
  22.         pDialog.setMessage("Buffering...");
  23.         pDialog.setIndeterminate(false);
  24.         pDialog.setCancelable(false);
  25.         // Show progressbar
  26.         pDialog.show();
  27.  
  28.         try {
  29.                 // Start the MediaController   
  30.                 MediaController mediacontroller = new MediaController(
  31.                         VideoViewActivity.this);
  32.                 mediacontroller.setAnchorView(videoview);
  33.                
  34.                 Method setVideoURIMethod = videoview.getClass().getMethod("setVideoURI", Uri.class, Map.class);
  35.                 Map<String, String> params = new HashMap<String, String>(1);
  36.                 String login = "usuario";
  37.                 String pwd = "contraseña";
  38.                 final String cred = login + ":" + pwd;
  39.                 final String auth = "Basic " + Base64.encodeToString(cred.getBytes("UTF-8"), 0);
  40.                 params.put("Authorization", auth);
  41.  
  42.                 // Get the URL from String VideoURL
  43.                 Uri video = Uri.parse(VideoURL);
  44.                 setVideoURIMethod.invoke(videoview, video, params);
  45.                 videoview.setMediaController(mediacontroller);
  46.                 videoview.setVideoURI(video);  
  47.  
  48.         } catch (Exception e) {
  49.             Log.e("Error", e.getMessage());
  50.             e.printStackTrace();
  51.         }
  52.         videoview.requestFocus();
  53.  
  54.         videoview.setOnPreparedListener(new OnPreparedListener() {
  55.             // Close the progress bar and play the video
  56.             public void onPrepared(MediaPlayer mp) {
  57.                 pDialog.dismiss();
  58.                 videoview.start();
  59.             }
  60.         });
  61.  
  62.     }
  63.  
  64. }

Última edición por razpeitia; 17/01/2015 a las 21:51