以下是活动代码
public class MainActivity extends Activity implements OnClickListener {private SurfaceVIEw surfaceVIEw;private button btnPlay;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); init(); addListener();}private voID init() { // Todo auto-generated method stub surfaceVIEw = (SurfaceVIEw) findVIEwByID(R.ID.surfaceVIEw1); btnPlay = (button) findVIEwByID(R.ID.btnPlay);}private voID addListener() { // Todo auto-generated method stub btnPlay.setonClickListener(this);}MediaPlayer mediaPlayer = null;@OverrIDepublic voID onClick(VIEw v) { // Todo auto-generated method stub switch (v.getID()) { case R.ID.btnPlay: try{ if (mediaPlayer != null) { mediaPlayer.reset(); mediaPlayer.release(); }else{ getwindow().setFormat(PixelFormat.UNKNowN); MediaPlayer mediaPlayer = MediaPlayer.create(this,R.raw.wildlife); SurfaceHolder surfaceHolder = surfaceVIEw.getHolder(); surfaceHolder.setFixedSize(176,144); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); mediaPlayer.setdisplay(surfaceHolder); mediaPlayer.start();} }catch (Exception e) { Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG).show(); } break; default: break; } } }
以下是xml的布局代码
<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:paddingBottom="@dimen/activity_vertical_margin"androID:paddingleft="@dimen/activity_horizontal_margin"androID:paddingRight="@dimen/activity_horizontal_margin"androID:paddingtop="@dimen/activity_vertical_margin"tools:context=".MainActivity" ><SurfaceVIEw androID:ID="@+ID/surfaceVIEw1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParentBottom="true" androID:layout_alignParentleft="true" androID:layout_alignParentRight="true" androID:layout_alignParenttop="true" /><button androID:ID="@+ID/btnPlay" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignRight="@+ID/surfaceVIEw1" androID:layout_aligntop="@+ID/surfaceVIEw1" androID:text="@string/play" /></relativeLayout>
请告诉我需要做什么?
提前致谢.
<SurfaceVIEwandroID:ID="@+ID/surfaceVIEw1"androID:layout_wIDth="fill_parent"androID:layout_height="fill_parent"androID:layout_alignParentBottom="true"androID:layout_alignParentleft="true"androID:layout_alignParentRight="true"androID:layout_alignParenttop="true" />总结
以上是内存溢出为你收集整理的android – 使用MediaPlayer类播放视频全部内容,希望文章能够帮你解决android – 使用MediaPlayer类播放视频所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)