无法播放视频

时间:2014-12-12 06:57:55

标签: java android

我正在尝试播放视频文件。但是它给了我错误(1,-1004)。我无法找到问题所在。

请帮助

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;


public class MainActivity extends Activity {
  VideoView videoView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        videoView= (VideoView)findViewById(R.id.video_view);

   videoView.setVideoURI(Uri.parse("http://192.168.1.234/hls-live/livepkgr/_definst_/liveevent/livestream.m3u8"));
     videoView.start();  



}
}

1 个答案:

答案 0 :(得分:0)

//试试这段代码

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;



public class MainActivity extends Activity {
  VideoView videoView;
  String VideoURL = "http://www.androidbegin.com/tutorial/AndroidCommercial.3gp";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        videoView= (VideoView)findViewById(R.id.video_view);

try {
       MediaController mediacontroller = new MediaController(
                    MainActivity.this);
            mediacontroller.setAnchorView(videoView);
           Uri video = Uri.parse(VideoURL);
            videoView.setMediaController(mediacontroller);
            videoView.setVideoURI(video);

         } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
         videoView.requestFocus();
        videoView.setOnPreparedListener(new OnPreparedListener() {

            public void onPrepared(MediaPlayer mp) {

                videoView.start();
            }
        }); 



}
}