抱歉,视频无法播放

时间:2012-10-06 11:40:07

标签: android video mp4

我的本​​地服务器中有一个视频文件。我正在为我的android代码提供视频文件的URL。我在Htdocs文件夹的视频文件夹中有视频文件。我在stackoverflow上查找了相同的问题,但找不到解决方案。请帮忙。这是代码..

public class WatchActivity extends Activity {

String SrcPath = "http://localhost/video/Coldplay - In My Place.mp4";

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
       myVideoView.setVideoURI(Uri.parse(SrcPath));
       myVideoView.setMediaController(new MediaController(this));
       myVideoView.requestFocus();
       myVideoView.start();
   }
}

这是这个

的logcat
10-06 12:02:11.473: D/MediaPlayer(332): Couldn't open file on client side, trying server side
10-06 12:02:11.523: E/MediaPlayer(332): error (1, -111)
10-06 12:02:11.723: E/MediaPlayer(332): Error (1,-111)
10-06 12:02:11.723: D/VideoView(332): Error: 1,-111
10-06 12:02:12.083: D/dalvikvm(332): GC_EXTERNAL_ALLOC freed 65K, 52% free 2609K/5379K, external 1813K/2137K, paused 50ms

1 个答案:

答案 0 :(得分:1)

首先你的链接错了。尝试使用10.0.2.2代替localhost

请尝试使用.3gp视频文件。

尝试使用以下链接。 http://daily3gp.com/vids/747.3gp

在清单文件中添加Internet权限。

<uses-permission android:name="android.permission.INTERNET"/>

修改:

VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
videoView.setMediaController(mc);
videoView.setVideoURI(Uri.parse("http://hermes.sprc.samsung.pl/widget/tmp/testh.3gp"));

videoView.requestFocus();
videoView.start();