Reputation: 793
I have a VideoView with all the Listeners defined and I'm trying to track down what to do if the network connection terminates during playback.
Currently the video just freezes, and the OnErrorListener is not called. The only way to recover is to press the back button.
Any ideas?
Upvotes: 0
Views: 686
Reputation: 793
I solved this by setting up a timer which checks for connectivity.
public class CheckNetworkConnection extends AsyncTask {
private boolean networkIsAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null;
}
@Override
protected String doInBackground(String... params) {
while (vv.isPlaying()) {
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
return "";
}
if ( !networkIsAvailable()) {
vv.stopPlayback();
VideoTime.this.finish();
}
}
return "";
}
}
Upvotes: 0
Reputation: 21507
A workaround might be to download the video file onto the sdcard (ex: with URLConnection and InputStream). I know for sure you could detect a network connection error during this download. Then when the download is done, the VideoView can play the video file directly from your local sdcard. The only issue with this is the VideoView must wait for the entire video to download before playing.
Upvotes: 1