问题
I'm testing an old app I created a while ago. The app is working on fiber WiFi, but if I use normal 3G connection the app crashes with a signal 6 VM error. I tried isolating the problem, I found out that it is caused by the setVideoURI method.
Here is my code:
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (videourl != null && videourI != null
&& extracted.contains(".mp4")) {
videoview.setOnPreparedListener(MainActivity.this);
mc = new MediaController(MainActivity.this);
mc.setMediaPlayer(videoview);
videoview.setVideoURI(videourI);
videoview.start();
save.setOnClickListener(MainActivity.this);
}
The problem seems to exist only on my Moto G with 4.4.4. Is this a known issue? And is there a workaround?
回答1:
VideoView.setVideoURI() starts a new thread for media playback, but it is the media decoding part which causes extra delay. so try to run that method on seperate Thread.
if (videourl != null && videourI != null && extracted.contains(".mp4"))
{
videoview.setOnPreparedListener(MainActivity.this);
mc = new MediaController(MainActivity.this);
mc.setMediaPlayer(videoview);
new Thread(new Runnable()
{
@Override
public void run()
{
videoview.setVideoURI(videourI); // make videoView final
runOnUiThread(new Runnable()
{
@Override
public void run()
{
videoview.start();
save.setOnClickListener(MainActivity.this);
}
});
}
}).start();
}
来源:https://stackoverflow.com/questions/26616513/setvideouri-causes-fatal-signal-6sigabrt