android-MediaPlayer的基本使用-播放音频视频

准备工作:

1.SurfaceView

provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen

2.SurfaceHolder

Abstract interface to someone holding a display surface. Allows you to control the surface size and format, edit the pixels in the surface, and monitor changes to the surface. This interface is typically available through theSurfaceView class.

3.MediaPlayer.

4.播放文件数据源

---------------------------------------------------------------------------------------------------------------------------------

<SurfaceView
     android:id="@+id/surfaceview"
     android:layout_width="320px"
     android:layout_height="240px"
 
  />

1.获得SurfaceView --------surfaceview=(SurfaceView)findViewById(R.id.surfaceview);

2.获得SurfaceHolder-------surfaceholder=surfaceview.getHolder();

              surfaceholder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);//设置显示内容是从外部压入的

               surfaceholder.addCallback(this);//此处需要一个实现SurfaceHolder.Callback接口的类实例



3.实例化一个播放器mediaplayer= new MediaPlayer();

        mediaplayer.setDataSource("http://www.bogotobogo.com/Video/sample.3gp");//设置数据源

        mediaplayer.setDisplay(surfaceholder);//设置显示到刚才的surfaceview

        mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);//设置流格式

        mediaplayer.prepare();

        mediaplayer.start();





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值