eclipse 中的 VideoView 无法在手机上播放
我在 Eclipse 中为 Android 应用程序放置了一个视频视图,但该视频无法在我的手机上播放。
package test.test;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class graphics extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.test);
MediaController mediaController = new MediaController (this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse("http://commonsware.com/misc/test2.3gp");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
}
I put a videoview in eclipse for an android app but the video will not play on my phone.
package test.test;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class graphics extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.test);
MediaController mediaController = new MediaController (this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse("http://commonsware.com/misc/test2.3gp");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题在于连接(http)或VideoView的使用。
要了解连接是否是问题,您可以尝试播放手机本地的媒体内容(即来自 SD 卡的媒体内容)。
问题还来自于 VideoView 的使用
VideoView 类使用 SurfaceView 和 MediaPlayer 来实现视频播放。 MediaPlayer 有 API 来设置 url、准备媒体管道、启动管道等。但在管道可以启动之前;管道必须准备好,即处于预卷状态。为了通知应用程序这一点,MediaPlayer 提供了侦听器。在本例中它是 onPrepareListener。
与 MediaPlayer 交互的 VideoView 也(必须?)提供这些侦听器。
看一下下面的 VideoPlayer 活动代码,它使用 VideoView 进行播放。 (仅针对本地内容进行验证)
此活动采用要根据意图播放的文件的绝对路径。 (从列表活动传递)
Shash
I think problem lies either with connectivity (http) or VideoView usage.
To know if the connectivity is the issue, you can try playing media content local to the phone, i.e. from SD Card.
Issues also be coming from VideoView usage
VideoView class uses SurfaceView and MediaPlayer to achieve Video Playback. MediaPlayer has APIs to set url, prepare the media pipeline, start the pipeline etc. But before pipeline can be started; the pipeline has to be ready i.e. in preroll condition. To notify application about this, MediaPlayer provides listeners. In this case it is onPrepareListener.
VideoView which interacts with MediaPlayer also (has to ?) provides these listeners as well.
Have a look below code for VideoPlayer activity which uses VideoView for playback. (Verified for local content only)
This activity takes absolute path to file to be played from intent. (passed from list activity)
Shash
检查您的手机是否已连接到互联网。在我看来,这可能是一个问题,因为您正在尝试播放来自 Uri 的视频。
Check whether your phone is connected to an Internet connection or not. In my view that might be a problem because you are trying to play a video from an Uri.