您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
12. 解决android8.0下opengles不能播放的问题和音频播放的回音问题~1
发布时间:2021-06-12 17:34:00编辑:雪饮阅读()
首先呢要在入口cpp/native-lib.cpp中初始化硬解編碼:
#include <jni.h>
#include <string>
#include <android/native_window_jni.h>
#include "FFDemux.h"
#include "XLog.h"
#include "FFDecode.h"
#include "XEGL.h"
#include "XShader.h"
#include "IVideoView.h"
#include "GLVideoView.h"
#include "FFResample.h"
#include "IAudioPlay.h"
#include "SLAudioPlay.h"
class TestObs:public IObserver
{
public:
void Update(XData d)
{
//XLOGI("TestObs Update data size is %d",d.size);
}
};
IVideoView *view = NULL;
extern "C"
JNIEXPORT
jint JNI_OnLoad(JavaVM *vm,void *res)
{
FFDecode::InitHard(vm);
///////////////////////////////////
///测试用代码
TestObs *tobs = new TestObs();
IDemux *de = new FFDemux();
//de->AddObs(tobs);
de->Open("/sdcard/v1080.mp4");
IDecode *vdecode = new FFDecode();
//vdecode->Open(de->GetVPara(), true);
vdecode->Open(de->GetVPara(), true);
IDecode *adecode = new FFDecode();
adecode->Open(de->GetAPara());
de->AddObs(vdecode);
de->AddObs(adecode);
view = new GLVideoView();
vdecode->AddObs(view);
IResample *resample = new FFResample();
XParameter outPara = de->GetAPara();
resample->Open(de->GetAPara(),outPara);
adecode->AddObs(resample);
IAudioPlay *audioPlay = new SLAudioPlay();
audioPlay->StartPlay(outPara);
resample->AddObs(audioPlay);
//vdecode->Open();
de->Start();
vdecode->Start();
adecode->Start();
return JNI_VERSION_1_4;
}
extern "C"
JNIEXPORT jstring
JNICALL
Java_com_example_xplay_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
//XLOGI("S begin!");
//XSleep(3000);
//XLOGI("S end!");
//return env->NewStringUTF(hello.c_str());
//XSleep(3000);
//de->Stop();
/*for(;;)
{
XData d = de->Read();
XLOGI("Read data size is %d",d.size);
}*/
return env->NewStringUTF(hello.c_str());
}
extern "C"
JNIEXPORT void JNICALL
Java_com_example_xplay_XPlay_InitView(JNIEnv *env, jobject instance, jobject surface) {
// TODO
ANativeWindow *win = ANativeWindow_fromSurface(env,surface);
view->SetRender(win);
//XEGL::Get()->Init(win);
//XShader shader;
//shader.Init();
}
#include <string>
#include <android/native_window_jni.h>
#include "FFDemux.h"
#include "XLog.h"
#include "FFDecode.h"
#include "XEGL.h"
#include "XShader.h"
#include "IVideoView.h"
#include "GLVideoView.h"
#include "FFResample.h"
#include "IAudioPlay.h"
#include "SLAudioPlay.h"
class TestObs:public IObserver
{
public:
void Update(XData d)
{
//XLOGI("TestObs Update data size is %d",d.size);
}
};
IVideoView *view = NULL;
extern "C"
JNIEXPORT
jint JNI_OnLoad(JavaVM *vm,void *res)
{
FFDecode::InitHard(vm);
///////////////////////////////////
///测试用代码
TestObs *tobs = new TestObs();
IDemux *de = new FFDemux();
//de->AddObs(tobs);
de->Open("/sdcard/v1080.mp4");
IDecode *vdecode = new FFDecode();
//vdecode->Open(de->GetVPara(), true);
vdecode->Open(de->GetVPara(), true);
IDecode *adecode = new FFDecode();
adecode->Open(de->GetAPara());
de->AddObs(vdecode);
de->AddObs(adecode);
view = new GLVideoView();
vdecode->AddObs(view);
IResample *resample = new FFResample();
XParameter outPara = de->GetAPara();
resample->Open(de->GetAPara(),outPara);
adecode->AddObs(resample);
IAudioPlay *audioPlay = new SLAudioPlay();
audioPlay->StartPlay(outPara);
resample->AddObs(audioPlay);
//vdecode->Open();
de->Start();
vdecode->Start();
adecode->Start();
return JNI_VERSION_1_4;
}
extern "C"
JNIEXPORT jstring
JNICALL
Java_com_example_xplay_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
//XLOGI("S begin!");
//XSleep(3000);
//XLOGI("S end!");
//return env->NewStringUTF(hello.c_str());
//XSleep(3000);
//de->Stop();
/*for(;;)
{
XData d = de->Read();
XLOGI("Read data size is %d",d.size);
}*/
return env->NewStringUTF(hello.c_str());
}
extern "C"
JNIEXPORT void JNICALL
Java_com_example_xplay_XPlay_InitView(JNIEnv *env, jobject instance, jobject surface) {
// TODO
ANativeWindow *win = ANativeWindow_fromSurface(env,surface);
view->SetRender(win);
//XEGL::Get()->Init(win);
//XShader shader;
//shader.Init();
}
爲了解決8.0opengles不能播放問題,還需要在方法surfaceCreated中setRenderer( this );處理下:XPlay.java:
package com.example.xplay;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
/**
* Created by Administrator on 2018-03-04.
*/
public class XPlay extends GLSurfaceView implements SurfaceHolder.Callback,GLSurfaceView.Renderer {
public XPlay(Context context, AttributeSet attrs) {
super( context, attrs );
}
@Override
public void surfaceCreated(SurfaceHolder holder)
{
//初始化opengl egl 显示
InitView(holder.getSurface());
//android 8.0 需要设置
setRenderer( this );
//只有在绘制数据改变时才绘制view,可以防止GLSurfaceView帧重绘
//setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
@Override
public void surfaceChanged(SurfaceHolder var1, int var2, int var3, int var4)
{
}
@Override
public void surfaceDestroyed(SurfaceHolder var1)
{
}
public native void InitView(Object surface);
@Override
public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
}
@Override
public void onSurfaceChanged(GL10 gl10, int i, int i1) {
}
@Override
public void onDrawFrame(GL10 gl10) {
}
}
雖然最後還是黑屏
但是老師測試的另外一個視頻是可以的是那個1080.mp4
关键字词:opengles
相关文章
-
无相关信息