Errors while using VideoView in Android
In the following sample code I am using the API demo app to play streaming videos
public class VideoViewDemo extends Activity {
/**
* TODO: Set the path variable to a streaming video URL or a local media
* file path.
*/
private String path = "";
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
mVideoView = (VideoView) findViewById(R.id.surface_view);
if (path == "") {
开发者_StackOverflow社区 // Tell the user to provide a media file URL/path.
Toast.makeText(
VideoViewDemo.this,
"Please edit VideoViewDemo Activity, and set path"
+ " variable to your media file URL/path",
Toast.LENGTH_LONG).show();
} else {
/*
* Alternatively,for streaming media you can use
* mVideoView.setVideoURI(Uri.parse(URLstring));
*/
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
}
}
But I face the following errors.
1> While playing the video, if there is an incoming call and if the user receives it and disconnects the call, then a black screen is displayed and the video is no longer played again.
2> Similarly if a user rejects an incoming call, a black screen is displayed and the video is no longer played.
3> When a low battery error message is displayed while a video is being played and the user clicks on OK button of the error message, a black screen is displayed and the video is no longer played.
4> When a SMS comes while viewing the streaming video and the user views the SMS and closes it, a black screen is displayed and the video is no longer played.
Kindly provide me the suggestions/sample code to handle these conditions and solve the errors.
if (path == "")
I don't think this works with strings.
rather
path.equals("") // returns true.
Though this may not actually fix your problems...
精彩评论