gpt4 book ai didi

android - VideoView 媒体播放器错误

转载 作者:行者123 更新时间:2023-11-29 00:07:09 24 4
gpt4 key购买 nike

我是 android 编程的新手,我正在尝试创建一个应用程序,该应用程序将通过我的服务器返回的 url 播放视频。我在我的项目中使用了 VideoView,但是当我运行我的应用程序时我的视频无法播放。我这里有我的 logcat 的屏幕截图和我的一些方法。请帮我解决我的问题。提前致谢。

screenshots here

public void playVideo(Uri uri)
{
progressBar.setVisibility(View.GONE);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();

progressBar.setVisibility(View.VISIBLE);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.start();
mp.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
@Override
public void onVideoSizeChanged(MediaPlayer mp, int arg1,
int arg2) {
// TODO Auto-generated method stub
progressBar.setVisibility(View.GONE);
mp.start();
}
});

}
});

videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

@Override
public void onCompletion(MediaPlayer mp) {
if (videoItem < adList.size() - 1) {
getVideo(videoItem++);
} else if(!waiting){/*
videoItem = 0;
getVideo();*/
videoItem = 0;
new GetVideoAdURLTask().execute(jsonURL + location);
}
else {
videoItem = 0;
getVideo(videoItem);
}
}
});
}

public synchronized void getVideo(final int n)
{
AsyncTask<String, Void, String> task = new AsyncTask<String, Void, String>()
{
@Override
public String doInBackground(String... urls)
{
uri = Uri.parse(adList.get(n));
Log.d("VIDFRAGMENT URI", String.valueOf(uri));

return null;
}

@Override
protected void onPostExecute(String result)
{
playVideo(uri);
}
};
task.execute();
}

最佳答案

试试这个

//your video url
String VideoURL = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the layout from video_main.xml
setContentView(R.layout.videoview_main);
// Find your VideoView in your video_main.xml layout
videoview = (VideoView) findViewById(R.id.VideoView);
// Execute StreamVideo AsyncTask

// Create a progressbar
pDialog = new ProgressDialog(VideoViewActivity.this);
// Set progressbar title
pDialog.setTitle("Android Video Streaming Tutorial");
// Set progressbar message
pDialog.setMessage("Buffering...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
// Show progressbar
pDialog.show();

try {
// Start the MediaController
MediaController mediacontroller = new MediaController(
VideoViewActivity.this);
mediacontroller.setAnchorView(videoview);
// Get the URL from String VideoURL
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() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
pDialog.dismiss();
videoview.start();
}
});

}

关于android - VideoView 媒体播放器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33023671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com