流媒体+软件应用+管理器

1、MediaPlayer播放音频与视频

  • 本地资源
  • 内部的URI,比如你可以通过ContentResolver来获取
  • 外部URL(流) 对于Android所支持的的媒体格式列表

1)获得MediaPlayer实例:

可以直接new或者调用create方法创建:

2)设置播放文件:

Note:另外setDataSource()方法有多个,里面有这样一个类型的参数:FileDescriptor,在使用这个 API的时候,需要把文件放到res文件夹平级的assets文件夹里,然后使用下述代码设置DataSource:

3)其他方法

  • getCurrentPosition( ):得到当前的播放位置
  • getDuration() :得到文件的时间
  • getVideoHeight() :得到视频高度
  • getVideoWidth() :得到视频宽度
  • isLooping():是否循环播放
  • isPlaying():是否正在播放
  • pause():暂停
  • prepare():准备(同步)
  • prepareAsync():准备(异步)
  • release():释放MediaPlayer对象
  • reset():重置MediaPlayer对象
  • seekTo(int msec):指定播放的位置(以毫秒为单位的时间)
  • setAudioStreamType(int streamtype):指定流媒体的类型
  • setDisplay(SurfaceHolder sh):设置用SurfaceHolder来显示多媒体
  • setLooping(boolean looping):设置是否循环播放
  • setOnBufferingUpdateListener(MediaPlayer.OnBufferingUpdateListener listener): 络流媒体的缓冲监听
  • setOnCompletionListener(MediaPlayer.OnCompletionListener listener): 络流媒体播放结束监听
  • setOnErrorListener(MediaPlayer.OnErrorListener listener): 设置错误信息监听
  • setOnVideoSizeChangedListener(MediaPlayer.OnVideoSizeChangedListener listener): 视频尺寸监听
  • setScreenOnWhilePlaying(boolean screenOn):设置是否使用SurfaceHolder显示
  • setVolume(float leftVolume, float rightVolume):设置音量
  • start():开始播放
  • stop():停止播放

本地Uri

外部URL

1.2 音频

1.3 视频SurfaceView

1.4 视频VideoView

1.5 相机

1.5.1 系统相机

2、Manager管理器

2.1 AudioManager(音频管理器)   https://www.runoob.com/w3cnote/android-tutorial-audiomanager.html

1)  获得AudioManager对象实例

AudioManager audiomanage = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);

2.2 Vibrator(振动器)    https://www.runoob.com/w3cnote/android-tutorial-vibrator.html

2.3 AlarmManager(闹钟服务)    https://www.runoob.com/w3cnote/android-tutorial-alarmmanager.html

2.4 PowerManager(电源服务)   https://www.runoob.com/w3cnote/android-tutorial-powermanager.html

2.5 WindowManager(窗口管理服务)    https://www.runoob.com/w3cnote/android-tutorial-windowmanager.html

2.6 LayoutInflater(布局服务)   https://www.runoob.com/w3cnote/android-tutorial-layoutinflater.html

①获取LayoutInflater实例的三种方法

2.7 WallpaperManager(壁纸管理器)  https://www.runoob.com/w3cnote/android-tutorial-wallpapermanager.html

 

 

 

 

 

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年2月14日
下一篇 2021年2月14日

相关推荐