2011-11-24 62 views
0

我的應用程序當前使用WebView,然後使用WebChromeClient,onShowCustomView轉到VideoView獲取視頻。但是,當我點擊視頻時,我不確定如何獲得正確的鏈接?它出現說,視頻不能播放,但這是因爲我根本沒有傳送視頻。我怎樣才能獲得點擊鏈接的網址?任何幫助?來自WebView的VideoView不會播放視頻?

這是web視圖的活動:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.mnwv_main); 

    myWebView = (WebView) findViewById(R.id.webview); 
    myWebView.getSettings().setJavaScriptEnabled(true); 
    myWebView.getSettings().setPluginsEnabled(true);  

    myWebView.setWebChromeClient(new WebChromeClient() { 

    public void onShowCustomView(View view, CustomViewCallback callback) { 
    super.onShowCustomView(view, callback); 
    videoURL = myWebView.getUrl(); 
    in= new Intent(MNWVMainPage.this,MainPageVideoHandler.class); 
    startActivity(in); } 
    });  

    myWebView.setWebViewClient(new WebViewClient()); 
    myWebView.loadUrl("http://www.meanwhileinwv.com"); 
} 

如果我點擊一個視頻,這個活動開始:

public class MainPageVideoHandler extends Activity { 

VideoView myVideoView; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.video_player); 

    myVideoView = (VideoView) findViewById(R.id.videoview); 
    MediaController mediaController = new MediaController(this); 
    mediaController.setAnchorView(myVideoView); 
    String video = (MNWVMainPage.videoURL); 
    myVideoView.setMediaController(mediaController); 
    myVideoView.setVideoPath(video); 
    myVideoView.start(); 


    myVideoView.setOnCompletionListener(new OnCompletionListener() {   
    @Override 
     public void onCompletion(MediaPlayer mp) { 
     mp.stop(); 
     myVideoView.stopPlayback(); 
     setContentView(R.layout.mnwv_main); 
     } 
    }); 

    myVideoView.setOnErrorListener(new OnErrorListener() { 
     @Override 
     public boolean onError(MediaPlayer mp, int what, int extra) { 
      return false; 
     } 
    });   
    } 
} 

回答