title: How to identify a video stream by using the MediaPlayer?
body: <p>I'm writing an application where I play a stream provided trough a URI. I would like to show the <code>SurfaceView</code> to render the video only if the stream is actually a video ... is it possibile?</p>
  <p>The code I'm using initialize <code>MediaPlayer</code> instance in this way:</p>
  <pre><code>private void initMediaPlayer(@NonNull final Context context) {
      media_player = new MediaPlayer();
      media_player.setAudioStreamType(AudioManager.STREAM_MUSIC);
  
      media_player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
          @Override
          public void onPrepared(MediaPlayer mp) {
              Log.d(getClass().getName(), &quot;onPreparedListener&quot;);
  
              //TODO: identify video/audio
  
              enablePlay();
          }
      });
  
      media_player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
          @Override
          public void onCompletion(MediaPlayer mp) {
              Log.d(getClass().getName(), &quot;onCompletionListener&quot;);
              Toast.makeText(context, getString(R.string.streaming_completed), Toast.LENGTH_LONG).show();
          }
      });
  
      media_player.setOnErrorListener(new MediaPlayer.OnErrorListener() {
          @Override
          public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
              error = true;
              Log.e(getClass().getName(), String.format(&quot;MediaPlayer error: %d, %d&quot;, i, i1));
              return false;
          }
      });
  }
  </code></pre>
  <p>I tought I can investigate the kind of stream inside <code>setOnPreparedListener</code> handler but as long as I can see there's no way to verify what the stream actually is.</p>
  <p>The streaming is started trough this method.</p>
  <pre><code>private void initStreaming(@NonNull final String uri) {
      new Thread(
              new Runnable() {
                  @Override
                  public void run() {
                      try {
                          media_player.setDataSource(uri);
                          media_player.prepareAsync();
                      } catch (Throwable e) {
                          Log.e(getClass().getName(), &quot;Exception: &quot; + e.getMessage());
                      }
                  }
              }
      ).start();
  }
  </code></pre>
  <p>===== UPDATE =====</p>
  <p>The uri specify a network stream not a local file therefore solution based on mime types or filename/extension will not work.</p>