Forgive me if this is a newbie question, but...
When playing video, is it better to use VideoView/MediaPlayer, or is it better to use intent.ACTION_VIEW and let the user select his/her media player?
The videos that I need to play are very large mp4 files (20 meg - 50+ meg) which are not optimized for mobile. I have buffering issues when using VideoView/MediaPlayer. However, when I use intent.ACTION_VIEW, I can use something like RealPlayer, which does a better job of buffering (at least in my case). Plus, RealPlayer and the other players I've tried handle orientation changes without restarting the video like VideoView/MediaPlayer do. However, I don't know if this second approach is "acceptable" from a user-experience perspective.
Here's the code for my VideoView/MediaPlayer approach:
XML:
<VideoView android:id="@+id/videoView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Java:
public class VideoViewActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse("http://www.my.big.video.com/video.mp4");
videoView.setMediaController(mediaController);
videoView.setVideo开发者_StackOverflow中文版URI(video);
videoView.start();
}
And here's the code for my second approach:
Java:
public class VideoViewActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String videoUrl = "http://www.my.big.video.com/video.mp4";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(videoUrl));
startActivity(i);
}
Suggestions?
You cannot assume the user has RealPlayer or any other specific media player so that approach is hoping the intent will open a media player which is able to handle the file well. To avoid the orientation change problem I locked the landscape of the VideoView to landscape (who wants to watch a video in portrait anyway?). I'm sure this is considered a cheap way out, but it works.
精彩评论