HTML5 视频 Android VideoView

发布于 2024-12-17 07:31:36 字数 1056 浏览 1 评论 0原文

我正在尝试在 VideoView 中播放从 WebView 传递的视频。它有效,但 VideoView 不想读取它。我不断收到错误消息:

“抱歉,该视频无法播放。”

以下是 VideoView 的代码:

public class VideoHandler extends Activity {

WebView myWebView;
VideoView myVideoView;
WebChromeClient chromeClient;
WebViewClient wvClient;
Intent in;

@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.myWebView.getUrl());
   myVideoView.setMediaController(mediaController);
   myVideoView.setVideoPath(video);
   myVideoView.start();


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

为什么无法加载视频?

I am trying to play a video that is passed from a WebView in a VideoView. It works, except VideoView does not want to read it. I keep getting the error:

"Sorry, this video cannot be played."

Here is the code for the VideoView:

public class VideoHandler extends Activity {

WebView myWebView;
VideoView myVideoView;
WebChromeClient chromeClient;
WebViewClient wvClient;
Intent in;

@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.myWebView.getUrl());
   myVideoView.setMediaController(mediaController);
   myVideoView.setVideoPath(video);
   myVideoView.start();


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

Why wont this load the video?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国粹 2024-12-24 07:31:36

仅从您的代码中读取,我看不到任何错误。
您可以检查一些事项:

  1. 视频是否符合格式列表此处

  2. 您是否打开了相机/另一个VideoView?即使你释放它们,缓冲区似乎也需要一些时间才能真正释放。

From just reading from your code, I can see no error.
Can you check a few things:

  1. Does the video align to the format list here?

  2. Have you open the camera/ another VideoView? Even if you release them, the buffer seems to need some time to be actually released.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文