Android多媒体播放功能的代码解析

移动开发 Android
我们在这篇文章中将会通过一段代码示例为大家详细解读有关Android多媒体播放的操作技巧。大家可以以此为参考对象,来掌握这一应用技巧。

我们曾经在其他文章中通过对录音以及录像的实现方法具体讲解过有关Android多媒体录制的相关操作技巧。在这里我们将会为大家详细介绍一下Android多媒体播放的应用方式,以帮助大家对这方面的应用知识有一个深刻的印象。

Android多媒体播放代码:

  1. import android.app.Activity;   
  2. import android.os.Bundle;   
  3. import android.view.View;   
  4. import android.view.View.OnClickListener;   
  5. import android.widget.Button;   
  6. import android.widget.VideoView;   
  7. public class VideoPlayer extends Activity   
  8. {   
  9. /**   
  10. Called when the activity is first created.   
  11. */ @Override   
  12. public void onCreate(Bundle icicle)   
  13. {   
  14. super.onCreate(icicle);   
  15. setContentView(R.layout.main);   
  16. final VideoView w =(VideoView)findViewById(R.id.vdoplayer);   
  17. Button cmdload = (Button)this.findViewById(R.id.cmd_load);   
  18. cmdload.setOnClickListener(new OnClickListener()  
  19. {   
  20. public void onClick(View arg0)   
  21. {   
  22. // TODO Auto-generated method stub   
  23. w.setVideoPath("/sdcard/android/kongfu.mp4");   
  24. }   
  25. }  
  26. );   
  27. Button cmdplay = (Button)this.findViewById(R.id.cmd_play);   
  28. cmdplay.setOnClickListener(new OnClickListener()  
  29. {   
  30. public void onClick(View arg0)   
  31. {   
  32. // TODO Auto-generated method stub   
  33. w.start();   
  34. }   
  35. }   
  36. );   
  37. Button cmdpause = (Button)this.findViewById(R.id.cmd_pause);   
  38. cmdpause.setOnClickListener(new OnClickListener()  
  39. {   
  40. public void onClick(View arg0)   
  41. {   
  42. // TODO Auto-generated method stub   
  43. w.pause();   
  44. }   
  45. }  
  46. );   
  47. }   
  48. }  
  49. main.xml: 

Android多媒体播放实现代码:

  1. < ?xml version="1.0" encoding="utf-8"?> 
  2. < LinearLayout xmlns:android=
    "http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
  3. < Button android:id="@+id/cmd_load" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="load" /> 
  4. < Button android:id="@+id/cmd_play" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="Play" /> 
  5. < Button android:id="@+id/cmd_pause" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:text="pause" /> 
  6. < VideoView android:id="@+id/vdoplayer" 
    android:layout_width="fill_parent" 
    android:layout_height="300px" /> 
  7. < /LinearLayout>  

Android多媒体播放的具体代码编写方式就为大家介绍到这里。

【编辑推荐】

  1. Android target类型选择技巧
  2. Android录音失真具体解决方案
  3. Android屏幕大小相关技巧应用指南
  4. Android多媒体录制功能的实现方式介绍
  5. Android图片大小调整动态实现方法
责任编辑:曹凯 来源: javaeye.com
相关推荐

2017-03-01 14:01:31

android多媒体音乐代码

2010-01-27 15:15:13

Android多媒体录

2013-12-17 13:29:04

iOS开发多媒体

2011-08-02 10:36:02

iOS开发 SDK 多媒体

2009-12-25 17:02:33

WPF多媒体

2009-02-18 17:15:51

Fedora 10多媒体播放解决方案

2011-06-24 10:21:11

Qt phonon 多媒体

2022-01-11 17:58:13

Android 代码操作系统

2021-09-13 15:15:18

鸿蒙HarmonyOS应用

2013-08-28 16:08:19

多媒体Windows8.1

2010-01-27 13:52:15

Android多媒体框

2022-11-25 16:39:03

视频播放鸿蒙

2022-11-23 14:43:40

2010-08-01 15:34:27

Android

2010-02-04 14:27:11

2018-05-25 14:37:58

2011-06-09 10:07:28

Qt phonon

2010-06-30 10:38:05

2018-02-07 15:35:04

2010-10-27 11:27:50

MAS视频监控H3C
点赞
收藏

51CTO技术栈公众号