2010-03-23 2 views
0

rtsp 링크를 스트리밍 할 수있는 작동하는 비디오 플레이어를 얻을 수 있었지만 UI에 비디오를 현재 시간 위치로 표시하는 방법을 모르지만, 나는 getDuration을 사용하고 getCurrentPosition은 문자열에이 정보를 저장하고 UI에 표시하려고 호출하지만rtsp 스트림의 비디오 정보를 Android 앱 UI에 표시하는 것이 가능합니다.

**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); 
    } 
    } 
}; 

답변

0

귀하의 코드 내 vidtry 샘플처럼 크게 보이는 일 것 같지 않습니다. getCurrentPosition()getDuration()은 진행률 표시 줄 업데이트와 같은 HTTP 스트리밍에서 작동합니다.

저는 RTSP 비디오 스트림으로 비디오를 시도하지 않았습니다. 왜냐하면 대부분 모르기 때문입니다.

0

는 응답 시간을 보내는 수 있도록 서버에서 SDP 응답을 확인 (라이브 스트림이 인식 할 수있는 시간이 없어하고이 정보를 제공하지 클라이언트를 발생할 수 있습니다.)

일예 같은 VoD 서비스 클립이 보일 것입니다 반면

a=range:npt=0- 

: 라이브 피드는 모양을

a=range:npt=0-399.1680 

getCurrentPosition() 경우가 작동하지 않습니다,하지만 당신은 알고있는 기간 (중 getDuration() 작품 또는 대체가 이 정보를 얻는 방법은 버퍼링 이벤트를보고이를 추적하여 접근 할 수 있습니다.이 방법보다 접근 방법이 더 바람직합니다.

0

맞았 으면 TextView에 표시하려고합니다. 시간 예 hh : mm : ss?

그렇다면 어떻게해야하는지 잠시 안내 드리겠습니다.

 
private TextView mElapsedTimeText; 
private VideoView mVideoView; 
private Thread mThread; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    /* here goes your code */ 

    // let's assume that your IDs are elapsedId and videoId 
    mElapsedTimeText = (TextView) findViewById(R.id.elapsedId); 
    mVideoView = (VideoView) findViewById(R.id.videoId); 


    mThread = new Thread() { 
     @Override 
     public void run() { 
      mElapsedTime.setText(getNiceString()); 
      mVideoView.postDelayed(mThread, 1000); 
     } 
    } 

    /* here goes your code */ 
} 

public String getNiceString() { 
    String result = ""; 
    int position = mVideoView.getCurrentPosition(); 

    /* here goes your code */ 

    //result is hh:mm:ss formatted string 
    return result; 
} 

@Override 
public void onPrepared(MediaPlayer mp) { 
    /* here goes your code */ 

    // you have to trigger the process somewhere 
    mVideoView.postDelayed(mThread, 1000); 

    /* here goes your code */ 
}  

그리고 내가 언급 한 것을 잊어 버렸습니다. 이 작업을 수행하려면 활동 클래스가 OnPreparedListener 인터페이스를 구현해야합니다.

본인이나 다른 사람이 유용하다고 생각합니다.

안부,

이고르

관련 문제