2013-07-09 130 views
1

我有這樣的方法,用於播放視頻:Videoview不玩視頻

private void changeVideoState() { 
    playing = !playing; 
    if (playing) { 
     videoView.start(); 
     play.setVisibility(View.GONE); 
     stop.setVisibility(View.VISIBLE); 
    } else { 
     videoView.stopPlayback(); 
     stop.setVisibility(View.GONE); 
     play.setVisibility(View.VISIBLE); 
    } 
} 

在第一時間調用方法時視頻已被播放。

但任何其他時間,當我嘗試撥打videoView.start()沒有任何反應。

這裏是videoview的初始化

videoView = (VideoView) findViewById(R.id.preview); 
    MediaController mc = new MediaController(getActivity()); 
    // mc.setAnchorView(videoView); 
    mc.setMediaPlayer(videoView); 
    videoView.setMediaController(mc); 
    videoView.setVideoURI(Uri.fromFile(file)); 
+0

是否顯示任何錯誤? – ridoy

回答

0

試試這個one.It工作正常,我..

VideoView videoView; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    videoView = (VideoView)findViewById(R.id.videoView);   
    videoView.setVideoPath("/sdcard/sample.3gp"); 
    videoView.start(); 
} 

或者,
把你的視頻在res/raw folder.And then ..

public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     showVideo(); 
    } 
private void showVideo() 
{ 
    VideoView vd = (VideoView)findViewById(R.id.videoView); 
    Uri uri = Uri.parse("android.resource://package/"+R.raw.movie); 
    MediaController mc = new MediaController(this); 
    vd.setMediaController(mc); 
    vd.setVideoURI(uri); 
    vd.start(); 
} 

當然試試它在真實的設備而不是模擬器。

+0

它在第一次工作,但我停止視頻'stopPlayback()',然後調用'videoView.start();'它再次不起作用。 – user1940676

+0

看到http://stackoverflow.com/questions/9290477/videoview-stop-display-when-activity-resumed-and-restart – ridoy

+0

我有一個'停止'和'開始'按鈕,當點擊一個它應該停止和再次開始視頻。 – user1940676