调用android 1.5的api可以播放mp4封装格式中的部分编码格式。
程序运行效果:
主要是调用android的媒体支持API,源代码:
package com.easymorse;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;public class Mp4PlayerActivity extends Activity {
VideoView videoView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);videoView = (VideoView) this.findViewById(R.id.videoView);
MediaController controller = new MediaController(this);
this.videoView.setMediaController(controller);
videoView.setVideoURI(Uri.parse("http://sayedhashimi.com/downloads/android/movie.mp4"));
videoView.requestFocus();
}
}
这里使用的mp4是《pro android》电子版中的示例。播放成功。但是发现其他mp4无法播放。原因是android 1.5 api尚不支持h.264编码。上面示例的视频编码格式divx。
见mplayer播放的属性:
源代码见:
留言列表