Android 原生 MediaPlayer 和 MediaCodec 的区别和联系(二)
目录:
(3)Android 官方网站 对 MediaPlayer的介绍
正文:
Android 官方网站 对 MediaPlayer的介绍
- 当使用 new 创建MediaPlayer对象或者在调用 reset() 之后,它处于空闲状态; 并且在调用 release() 之后,它处于 End 状态。 在这两个状态之间是MediaPlayer对象的生命周期。
- 通常,一些播放控制操作可能由于各种原因而失败,例如不支持的音频/视频格式,交错的音频/视频,分辨率太高,流超时等。因此,在这些情况下,关注错误报告和恢复是非常重要的。有时,由于编程错误,也可能在无效状态下调用播放控制操作。在所有这些错误条件下,如果开发者事先通过setOnErrorListener(android.media.MediaPlayer.OnErrorListener)注册了 OnErrorListener ,则内部播放器引擎会调用开发者提供的 OnErrorListener.onError() 方法。
- 调用 setDataSource(FileDescriptor), 或 setDataSource(String), 或 setDataSource(Context, Uri), 或 setDataSource(FileDescriptor, long, long), 或 setDataSource(MediaDataSource)
- 在开始播放之前,MediaPlayer 对象必须先进入准备状态。
- 要开始播放,必须调用 start() ,start() 返回成功后,MediaPlayer对象则处于 Started状态(Started state)。isPlaying()可用来测试 MediaPlayer对象是否处于 Started状态(Started state)。
- 播放可以暂停和停止,并可以调整当前播放位置。 可以通过pause()暂停播放。 当对pause()的调用返回时,MediaPlayer对象进入Paused状态(Pausedstate)。 请注意,从“已启动”状态(Started state)到“暂停”状态(Paused state)的转换(反之亦然)在播放器引擎中异步发生。 在调用isPlaying()时更新状态可能需要一些时间,对于流内容,它可能需要几秒钟。
- 调用stop()会停止播放并导致处于Started,Paused,Prepared或PlaybackCompleted状态(state)的MediaPlayer进入Stopped状态(Stopped state)。
- 可以通过调用seekTo(long, int)调整播放位置
- 当播放到达流的结尾时,播放完成。
Method Name | Valid Sates | Invalid States | Comments |
attachAuxEffect | {Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted} | {Idle, Error} | This method must be called after setDataSource. Calling it does not change the object state. |
getAudioSessionId | any | {} | This method can be called in any state and calling it does not change the object state. |
getCurrentPosition | {Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted} | {Error} | Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state. |
getDuration | {Prepared, Started, Paused, Stopped, PlaybackCompleted} | {Idle, Initialized, Error} | Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state. |
getVideoHeight | {Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted} | {Error} | Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state. |
getVideoWidth | {Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted} | {Error} | Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state. |
isPlaying | {Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted} | {Error} | Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state. |
pause | {Started, Paused, PlaybackCompleted} | {Idle, Initialized, Prepared, Stopped, Error} | Successful invoke of this method in a valid state transfers the object to the Paused state. Calling this method in an invalid state transfers the object to the Error state. |
prepare | {Initialized, Stopped} | {Idle, Prepared, Started, Paused, PlaybackCompleted, Error} | Successful invoke of this method in a valid state transfers the object to the Prepared state. Calling this method in an invalid state throws an IllegalStateException. |
prepareAsync | {Initialized, Stopped} | {Idle, Prepared, Started, Paused, PlaybackCompleted, Error} | Successful invoke of this method in a valid state transfers the object to the Preparing state. Calling this method in an invalid state throws an IllegalStateException. |
release | any | {} | After release(), the object is no longer available. |
reset | {Idle, Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted, Error} | {} | After reset(), the object is like being just created. |
seekTo | {Prepared, Started, Paused, PlaybackCompleted} | {Idle, Initialized, Stopped, Error} | Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state. |
setAudioAttributes | {Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackCompleted} | {Error} | Successful invoke of this method does not change the state. In order for the target audio attributes type to become effective, this method must be called before prepare() or prepareAsync(). |
setAudioSessionId | {Idle} | {Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted, Error} | This method must be called in idle state as the audio session ID must be known before calling setDataSource. Calling it does not change the object state. |
setAudioStreamType (deprecated) | {Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackCompleted} | {Error} | Successful invoke of this method does not change the state. In order for the target audio stream type to become effective, this method must be called before prepare() or prepareAsync(). |
setAuxEffectSendLevel | any | {} | Calling this method does not change the object state. |
setDataSource | {Idle} | {Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted, Error} | Successful invoke of this method in a valid state transfers the object to the Initialized state. Calling this method in an invalid state throws an IllegalStateException. |
setDisplay | any | {} | This method can be called in any state and calling it does not change the object state. |
setSurface | any | {} | This method can be called in any state and calling it does not change the object state. |
setVideoScalingMode | {Initialized, Prepared, Started, Paused, Stopped, PlaybackCompleted} | {Idle, Error} | Successful invoke of this method does not change the state. |
setLooping | {Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackCompleted} | {Error} | Successful invoke of this method in a valid state does not change the state. Calling this method in an invalid state transfers the object to the Error state. |
isLooping | any | {} | This method can be called in any state and calling it does not change the object state. |
setOnBufferingUpdateListener | any | {} | This method can be called in any state and calling it does not change the object state. |
setOnCompletionListener | any | {} | This method can be called in any state and calling it does not change the object state. |
setOnErrorListener | any | {} | This method can be called in any state and calling it does not change the object state. |
setOnPreparedListener | any | {} | This method can be called in any state and calling it does not change the object state. |
setOnSeekCompleteListener | any | {} | This method can be called in any state and calling it does not change the object state. |
setPlaybackParams | {Initialized, Prepared, Started, Paused, PlaybackCompleted, Error} | {Idle, Stopped} | This method will change state in some cases, depending on when it's called. |
setScreenOnWhilePlaying | any | {} | This method can be called in any state and calling it does not change the object state. |
setVolume | {Idle, Initialized, Stopped, Prepared, Started, Paused, PlaybackCompleted} | {Error} | Successful invoke of this method does not change the state. |
setWakeMode | any | {} | This method can be called in any state and calling it does not change the object state. |
start | {Prepared, Started, Paused, PlaybackCompleted} | {Idle, Initialized, Stopped, Error} | Successful invoke of this method in a valid state transfers the object to the Started state. Calling this method in an invalid state transfers the object to the Error state. |
stop | {Prepared, Started, Stopped, Paused, PlaybackCompleted} | {Idle, Initialized, Error} | Successful invoke of this method in a valid state transfers the object to the Stopped state. Calling this method in an invalid state transfers the object to the Error state. |
getTrackInfo | {Prepared, Started, Stopped, Paused, PlaybackCompleted} | {Idle, Initialized, Error} | Successful invoke of this method does not change the state. |
addTimedTextSource | {Prepared, Started, Stopped, Paused, PlaybackCompleted} | {Idle, Initialized, Error} | Successful invoke of this method does not change the state. |
selectTrack | {Prepared, Started, Stopped, Paused, PlaybackCompleted} | {Idle, Initialized, Error} | Successful invoke of this method does not change the state. |
deselectTrack | {Prepared, Started, Stopped, Paused, PlaybackCompleted} | {Idle, Initialized, Error} | Successful invoke of this method does not change the state. |
转载于:https://www.cnblogs.com/nmj1986/p/9307588.html
Android 原生 MediaPlayer 和 MediaCodec 的区别和联系(二)相关推荐
- android原生MediaPlayer播放本地的m3u8
背景 遇到某个需求,需要播放百度网盘的视频.但是通过百度网盘的sdk获取到的视频url是由若干个ts片段组成的m3u8播放源.然后把这个m3u8的播放源放在本地,也就是说m3u8是一个本地播放源.那么 ...
- MediaPlayer和Mediacodec还有AudioTrack的关系
1.mediaplayer android P MediaCodec编解码流程分析_三火哥的博客-CSDN博客_android 视频解码流程图 android P MediaCodec编解码流程分析_ ...
- 【小王的安卓之路】Android原生网络请求
Android原生网络请求 一. 网络请求的必要性 二. 网络请求分类 三. 网络请求实现方法 四. 注意事项 一.网络请求的必要性: 如今单机APP早已经接近消失就连最简单的时钟日期等软件都需要去请 ...
- zbar android解码错误,Android原生编解码接口 MediaCodec 之——踩坑
关键帧 MediaCodec 有两种方式触发输出关键帧,一是由配置时设置的 KEY_FRAME_RATE和KEY_I_FRAME_INTERVAL参数自动触发,二是运行过程当中经过 setParame ...
- Android 抛弃原生MediaPlayer 使用音频框架 StarrySky
前言 最近用原生MediaPlayer 各种无法解决的问题 于是找第三方优秀框架 推荐 音频框架 StarrySky 亲测效果极佳 是满意的效果! StarrySky音频框架 项目依赖 需要在工程的b ...
- Android原生编解码接口 MediaCodec 之——完全解析
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/gb702250823/article/ ...
- Android音视频API - MediaCodec/MediaMuxer/MediaStore/MediaController等
AudioTrack播放音频PCM.[Android] 混音器AudioMixer. MediaPlayer/MediaRecorder, AudioTrack/AudioRecorder, Medi ...
- 视屏播放_使用原生MediaPlayer+TextureView实现全屏、小窗口、视频列表、m3u8监控播放
Android 视屏播放器----MediaPlayer+TextureView实现全屏.小窗口.视频列表播放 标签(空格分隔): 视屏播放器 一.效果图 二.集成步骤 按文件目录复制进自己项目[文件 ...
- android studio放置在函数上面看_像写Flutter一样开发Android原生应用
要问到Flutter和Android原生App,在开发时有何区别,编程方式是绕不开的话题.Flutter采用声明式编程,Android原生开发则采用命令式编程. 声明式编程 VS. 命令式编程 我们首 ...
- Android中style和theme的区别
在学习Xamarin android的过程中,最先开始学习的还是熟练掌握android的六大布局-LinearLayout .RelativeLayout.TableLayout.FrameLayou ...
最新文章
- Java学习之if语句
- 单轮MapReduce的矩阵乘法
- 快速搞懂ThreadLocal实现原理
- wordpress html页面缓存 cdn,WordPress 下老旧又高效的本地缓存插件 cos-html-cache
- C++:编译实验之递归下降分析器
- 为什么全栈开发对物联网至关重要?
- AS3,ReferenceError: Error #1056: 无法为 ×× 创建属性 ×××。
- 广义积分中值定理的证明(柯西中值定理)
- win10使用命令提示符启用/关闭远程桌面
- 工业机器人——机械手臂
- Win10自带的录屏功能怎么使用?
- 小鼠大脑解剖图分区_大鼠解剖图_求助:大鼠#47;小鼠脑部解剖图谱
- 任务分解法[WBS]
- QT 如何去除QListView选中item后的虚线框
- 元宇宙时代,服装品牌们如何成为“头号玩家”?
- 计算机电源寿命,影响电脑寿命的几个重要方面
- 数据结构点餐管理系统java,C语言实现餐饮点餐管理系统
- 红米2联通4G版_标注:2014811_官方线刷包_救砖包_解账户锁
- 验证证书链 java_java实现证书链和签名验证
- 用了十年竟然都不对,Java、Rust、Go主流编程语言的哈希表比较
热门文章
- Java中,异常处理try catch的作用域是局部的
- iOS 浅复制和深复制的深层理解,含示例
- Away3D 的实体收集器流程2
- 为Chrome添加Metro风格的快速拨号
- struts2的struts.xml的详细配置1-1
- wireshark学习使用
- mac版有道云笔记切换笔记后内容仍展示前一个笔记内容问题解决
- python 边缘计算_OpenEdge首页、文档和下载 - 边缘计算平台 - OSCHINA - 中文开源技术交流社区...
- uat测试用例怎么写_测试用例怎么写?
- h5+js调取相机做取景框_iPhone 12 相机操作指南,用好了随手一拍就是大片!