2011-12-15 53 views
0

任何人都可以指導我如何播放特定時間的視頻? 我有一個視頻網址,我需要從特定的時間播放視頻,我用seekTo(),但它不工作。所以我認爲首先我們需要將視頻流式傳輸到一個文件,然後我們需要播放...但我不知道如何從網址流式傳輸視頻。如何在Android中從特定時間流式傳輸視頻?

任何人都可以提供我的示例代碼。

謝謝。

回答

2

喜試試下面的它會幫助你

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <VideoView android:id="@+id/playvideo" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:keepScreenOn="true" 
     android:layout_centerInParent="true"></VideoView> 



</RelativeLayout> 

安卓

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.videolayout); 
     this.videoView=(VideoView)findViewById(R.id.playvideo); 


     play(); 

    } 
    private void play(){ 
      MediaController mediaController = new MediaController(this); 
      mediaController.setAnchorView(this.videoView); 

     Uri video=Uri.parse("http://your.mp4/35.mp4"); 
      Log.e("Uri video",video.toString()); 
      videoView.setMediaController(mediaController); 
      videoView.setVideoURI(video);  
      videoView.seekTo(60000*10);//10 mins... 
      videoView.start(); 
      videoView.setOnCompletionListener(new OnCompletionListener(){ 

       public void onCompletion(MediaPlayer arg0) { 
        // TODO Auto-generated method stub 

       } 

      }); 
    } 
+0

謝謝你這麼多Sunriser ... – Taruni 2011-12-21 05:59:02