Android---mediaplayer 创建和调用顺序
Android mediaframework创建mediaplayer
// java层
///frameworks/base/media/java/android/media/MediaPlayer.java
public MediaPlayer() {
...
native_setup(new WeakReference<MediaPlayer>(this));
baseRegisterPlayer();
}
// native层
///frameworks/base/media/jni/android_media_MediaPlayer.cpp
//将函数native_setup映射为android_media_MediaPlayer_native_setup
{"native_setup", "(Ljava/lang/Object;)V",
(void*)android_media_MediaPlayer_native_setup},
android_media_MediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this)
{
sp<MediaPlayer> mp = new MediaPlayer();
if (mp == NULL) {
jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
return;
}
sp<JNIMediaPlayerListener> listener = new JNIMediaPlayerListener(env, thiz, weak_this);
mp->setListener(listener);
setMediaPlayer(env, thiz, mp);
}
Android mediaframework调用setDatasource
// java层
///frameworks/base/media/java/android/media/MediaPlayer.java
void setDataSource(String path, String[] keys, String[] values,
List<HttpCookie> cookies)
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
...
if ("file".equals(scheme)) {
path = uri.getPath();
} else if (scheme != null) {
// handle non-file sources
nativeSetDataSource(MediaHTTPService.createHttpServiceBinderIfNecessary(path, cookies), path, keys, values);
return;
}
}
// 这两个函数是native层的代码,并且在库 'libmedia_jni.so'中例如 :System.loadLibrary("media_jni");
private native void nativeSetDataSource(IBinder httpServiceBinder, String path, String[] keys,
String[] values)throws IOException, IllegalArgumentException,
SecurityException, IllegalStateException;
private native void _setDataSource(FileDescriptor fd, long offset, long length)
throws IOException, IllegalArgumentException, IllegalStateException;
// native层
///frameworks/base/media/jni/android_media_MediaPlayer.cpp
//将函数nativeSetDataSource映射为android_media_MediaPlayer_setDataSourceAndHeaders
static const JNINativeMethod gMethods[] = {
{
"nativeSetDataSource",
"(Landroid/os/IBinder;Ljava/lang/String;[Ljava/lang/String;"
"[Ljava/lang/String;)V",
(void *)android_media_MediaPlayer_setDataSourceAndHeaders
}
...
}
static void android_media_MediaPlayer_setDataSourceAndHeaders(
JNIEnv *env, jobject thiz, jobject httpServiceBinderObj, jstring path,
jobjectArray keys, jobjectArray values) {
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
if (mp == NULL ) {
jniThrowException(env, "java/lang/IllegalStateException", NULL);
return;
}
...
status_t opStatus =
mp->setDataSource(
httpService,
pathStr,
headersVector.size() > 0? &headersVector : NULL);
...
}
/frameworks/av/media/libmedia/mediaplayer.cpp
status_t MediaPlayer::setDataSource(
const sp<IMediaHTTPService> &httpService,
const char *url, const KeyedVector<String8, String8> *headers)
{
status_t err = BAD_VALUE;
if (url != NULL) {
// 获取mediaserver系统服务进程中的MediaPlayerService的
const sp<IMediaPlayerService> service(getMediaPlayerService());
if (service != 0) {
// 创建一个MediaPlayer代理
sp<IMediaPlayer> player(service->create(this, mAudioSessionId));
...
err = attachNewPlayer(player); // mPlayer = player;
}
}
return err;
}
最新文章
- freeCodeCamp:Where do I belong
- ArcGIS中的WKID
- linux下设置进程优先级方法!
- 【leetcode】triangle(easy)
- Python之调用函数
- JavaScript表单处理(下)
- 在Ubuntu 14.04 上安装网易云音乐
- java io InputStream 转 byte
- 【转载】【JQuery学习】jQuery插件开发
- Install GTK in Ubuntu
- VC一些经验系列: 《分享泄漏检测工具:内存、DC、GDI、Handle... 》
- PL/SQL 触发器简介
- tomcat server.xml 配置示例
- CDH 无法查看history log
- python获取绑定的IP,并动态指定出口IP
- 大型网站架构演进(6)使用NoSQL和搜索引擎
- [ASP.NET]ScriptManager控件使用 转载
- 泛微云桥e-Bridge安装手册
- Java - 25 Java 接口
- ubuntu 手动修改分辨率为1920 X 1080 的两种方式
热门文章
- defineProperty和Proxy
- Django中的app模型细节TypeError: __init__() missing 1 required positional argument: &#39;on_delete&#39; 解决办法
- Python系统模块os.py和sys.py常用函数
- npm vue-router安装报错
- 看到项目中的DateTimeFormat和JsonFormat就头大
- vim替换查找缩进操作
- Zookeeper ZAB协议
- Linux下查找并杀死 zombile 和 stopped 进程
- iphone tabbar问题
- phaclon 初学者遇到的问题!