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;

}

最新文章

  1. freeCodeCamp:Where do I belong
  2. ArcGIS中的WKID
  3. linux下设置进程优先级方法!
  4. 【leetcode】triangle(easy)
  5. Python之调用函数
  6. JavaScript表单处理(下)
  7. 在Ubuntu 14.04 上安装网易云音乐
  8. java io InputStream 转 byte
  9. 【转载】【JQuery学习】jQuery插件开发
  10. Install GTK in Ubuntu
  11. VC一些经验系列: 《分享泄漏检测工具:内存、DC、GDI、Handle... 》
  12. PL/SQL 触发器简介
  13. tomcat server.xml 配置示例
  14. CDH 无法查看history log
  15. python获取绑定的IP,并动态指定出口IP
  16. 大型网站架构演进(6)使用NoSQL和搜索引擎
  17. [ASP.NET]ScriptManager控件使用 转载
  18. 泛微云桥e-Bridge安装手册
  19. Java - 25 Java 接口
  20. ubuntu 手动修改分辨率为1920 X 1080 的两种方式

热门文章

  1. defineProperty和Proxy
  2. Django中的app模型细节TypeError: __init__() missing 1 required positional argument: &#39;on_delete&#39; 解决办法
  3. Python系统模块os.py和sys.py常用函数
  4. npm vue-router安装报错
  5. 看到项目中的DateTimeFormat和JsonFormat就头大
  6. vim替换查找缩进操作
  7. Zookeeper ZAB协议
  8. Linux下查找并杀死 zombile 和 stopped 进程
  9. iphone tabbar问题
  10. phaclon 初学者遇到的问题!