is it possible to display video information from an rtsp stream in an android app UI

Posted by Joseph Cheung on Stack Overflow See other posts from Stack Overflow or by Joseph Cheung
Published on 2010-03-23T08:54:57Z Indexed on 2010/05/17 14:00 UTC
Read the original article Hit count: 311

I have managed to get a working video player that can stream rtsp links, however im not sure how to display the videos current time position in the UI, i have used the getDuration and getCurrentPosition calls, stored this information in a string and tried to display it in the UI but it doesnt seem to work

in main.xml: TextView android:id="@+id/player" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="1px" android:text="@string/cpos" />

in strings.xml:

string name="cpos">"" /string>

in Player.java

private void playVideo(String url) { try { media.setEnabled(false);

if (player == null) { player = new MediaPlayer(); player.setScreenOnWhilePlaying(true); } else { player.stop();
player.reset(); }

player.setDataSource(url); player.getCurrentPosition(); player.setDisplay(holder); player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.setOnPreparedListener(this); player.prepareAsync(); player.setOnBufferingUpdateListener(this); player.setOnCompletionListener(this);

} catch (Throwable t) { Log.e(TAG, "Exception in media prep", t); goBlooey(t); try { try { player.prepare(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.v(TAG, "Duration: ===> " + player.getDuration()); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace();

} } }

private Runnable onEverySecond = new Runnable() { public void run() { if (lastActionTime > 0 && SystemClock.elapsedRealtime() - lastActionTime > 3000) { clearPanels(false); }

if (player != null) { timeline.setProgress(player.getCurrentPosition()); //stores getCurrentPosition as a string cpos = String.valueOf(player.getCurrentPosition()); System.out.print(cpos);

}

if (player != null) { timeline.setProgress(player.getDuration()); //stores getDuration as a string cdur = String.valueOf(player.getDuration()); System.out.print(cdur); }

if (!isPaused) { surface.postDelayed(onEverySecond, 1000); } } };

© Stack Overflow or respective owner

Related posts about android

Related posts about video-streaming