我正在尝试播放视频文件。但是它给了我错误(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();
}
}
答案 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();
}
});
}
}