public class MainActivity extends ActionBarActivity {
MediaPlayer _videoPlayer;
private SurfaceHolder holder;
private SurfaceView mPreview;
final String url = "http://xxxx/xxx/index.m3u8";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_videoPlayer = new MediaPlayer();
_videoPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
_videoPlayer.start();
}
});
mPreview = (SurfaceView)findViewById(R.id.surfaceView);
holder = mPreview.getHolder();
holder.addCallback(new SurfaceHolder.Callback(){
@Override
public void surfaceCreated(SurfaceHolder holder) {
_videoPlayer.setDisplay(holder);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if(_videoPlayer != null) {
_videoPlayer.setDisplay(null);
}
}
});
try {
// Uri uri = Uri.parse(url);
// _videoPlayer.setDataSource(this, uri);
_videoPlayer.setDataSource(url);
_videoPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
}
MediaPlayer _videoPlayer;
private SurfaceHolder holder;
private SurfaceView mPreview;
final String url = "http://xxxx/xxx/index.m3u8";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_videoPlayer = new MediaPlayer();
_videoPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
_videoPlayer.start();
}
});
mPreview = (SurfaceView)findViewById(R.id.surfaceView);
holder = mPreview.getHolder();
holder.addCallback(new SurfaceHolder.Callback(){
@Override
public void surfaceCreated(SurfaceHolder holder) {
_videoPlayer.setDisplay(holder);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if(_videoPlayer != null) {
_videoPlayer.setDisplay(null);
}
}
});
try {
// Uri uri = Uri.parse(url);
// _videoPlayer.setDataSource(this, uri);
_videoPlayer.setDataSource(url);
_videoPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
}
댓글
댓글 쓰기