Android 2.2 VideoView问题
我想播放 SD 卡上的电影。我尝试使用以下代码:
VideoView videoView = (VideoView) findViewById(R.id.videoView);
final String MEDIA_PATH = new String("/sdcard/robot.avi");
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setVideoPath(MEDIA_PATH);
videoView.setMediaController(mediaController);
videoView.start();
但是当我尝试播放该文件时,我收到一条错误消息。 “找不到视频”或类似的内容。当我尝试从网络流式传输时,视频可以正常播放,但速度很慢。在我的应用程序中播放视频的最佳方式是什么?
谢谢
I want to play a movie from my sd-card. Ive tried using the following code:
VideoView videoView = (VideoView) findViewById(R.id.videoView);
final String MEDIA_PATH = new String("/sdcard/robot.avi");
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setVideoPath(MEDIA_PATH);
videoView.setMediaController(mediaController);
videoView.start();
But when Im trying to play the file i get an error message. "video not found" or something similar. When i tried streaming from the web, the video worked but was very laggy. Whats the best way to play videos in my app?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
试试这个...
Try this...
据观察,
setVideoPath()
失败,而setVideoURI()
对于 Web 和本地都运行良好,所以我坚持您使用它。It is observed that
setVideoPath()
fails, whilesetVideoURI()
works well for both Web and Local so I insist you to use this.使用此代码。希望它能起作用
Use this code.Hope it will work
尝试一下,
如果您尝试设置为 uri,则不能直接作为字符串路径传递。对我来说工作正常的代码:
Try with
you can not pass directly as a string path if you are trying to set as a uri. The code which is working fine for me :
您的问题是视频路径设置不正确:
只需切换到此代码:
如果视频“robot.avi”存在于 sd 卡的根文件夹中,这将解决您的问题
your problem is that the video path is not set the right way:
just switch to this code:
that will solve your problem if the video "robot.avi" exists on the root folder of the sd card
您正在自己的
VideoView
中播放视频,但是,如果您没有任何可自定义的内容,只想在屏幕上显示视频,为什么不使用默认播放器来播放视频呢?
You are playing your video in your own
VideoView
,But if you have nothing to customize and just want to show the video in the screen,why dont you use the default player to play the video.
可能是android不支持avi。将其转换为mp4或wmv或3gp。
试试这个代码
May be avi does not support in android.convert it into mp4 or wmv or 3gp.
try this code