public class AvplayerActivity extends Activity {
static int RENDER_ANDROID_OGL = 0;
AndroidVideoWindowImpl m_window;
Thread m_sThread;
boolean m_res = false;
static {
System.loadLibrary("avplayer");
}
@SuppressWarnings("static-access")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_avplayer);
Log.v("java","onCreate");
GLSurfaceView view = (GLSurfaceView) findViewById(R.id.video_surface);
view.setZOrderOnTop(false);
m_window = new AndroidVideoWindowImpl(view,null);
m_window.init();
URLDecoder d = new URLDecoder();
Intent intent = getIntent();
String filename = intent.getDataString();
if(filename == null)
{
filename = "rtmp://121.93.185.123/g";
}
if(filename != null){
try {
filename = d.decode(filename, "utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
AvplayerNative.AvplayInit();
AvplayerNative.AvplaySetWindowHandle(m_window);
m_res = AvplayerNative.AvplayOpen(filename, 5, RENDER_ANDROID_OGL);
if(m_res){
m_sThread = new Thread() {
public void run() {
AvplayerNative.AvpalyPlay(0,0);
};
};
/* start */
m_sThread.start();
}
else{
dialog("Vidoe Format Error");
}
}
}
@Override
protected void onStop(){
Log.v("java","onStop1");
super.onStop();
Log.v("java","onStop");
}
@Override
protected void onRestart(){
Log.v("java","onRestart1");
super.onRestart();
Log.v("java","onRestart");
}
@Override
protected void onDestroy(){
super.onDestroy();
Log.v("java","onDestroy1");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_avplayer, menu);
return true;
}
protected void dialog(String msg) {
AlertDialog.Builder builder = new Builder(this);
builder.setMessage(msg);
builder.setTitle("是否退出");
builder.setPositiveButton("退出",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
AvplayerNative.AvplayClose();
Log.e("java","AvplayClose");
AvplayerActivity.this.finish();
}
});
builder.setNegativeButton("OK",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});