android平台调用vlc播放器的例子
来源:互联网 发布:淘宝店铺规划 编辑:程序博客网 时间:2024/05/18 03:12
做为一个android平台vlc的测试程序,例子只有简单的播放、停止功能,界面只有四个控件,播放、停止按钮,设置url,显示surface。
稳定性遗憾的是vlc不能对接上openmax硬解。
vlc版本:vlc-2.0.0
package org.videolan.vlc;
import java.io.IOException;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.SurfaceHolder.Callback;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
public class vlcplayerActivity extends Activity {
/** Called when the activity is first created. */
public class ClickEvent implements OnClickListener {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==mplayerbtn)
{
try {
mLibVLC.readMedia(murlPath.getText().toString());
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else if(v==mstopbtn)
{
mLibVLC.stop();
}
}
}
public final static String TAG = "VLC/VideoPlayerActivity";
private Button mplayerbtn = null;
private Button mstopbtn = null;
private SurfaceView mvideoserface = null;
private SurfaceHolder surfaceHolder;
private EditText murlPath = null;
private LibVLC mLibVLC;
// size of the video
private int mVideoHeight;
private int mVideoWidth;
private static final int SURFACE_SIZE = 3;
private static final int SURFACE_BEST_FIT = 0;
private static final int SURFACE_FIT_HORIZONTAL = 1;
private static final int SURFACE_FIT_VERTICAL = 2;
private static final int SURFACE_FILL = 3;
private static final int SURFACE_16_9 = 4;
private static final int SURFACE_4_3 = 5;
private static final int SURFACE_ORIGINAL = 6;
private int mCurrentSize = SURFACE_BEST_FIT;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mplayerbtn = (Button)findViewById(R.id.btnplay);
mstopbtn = (Button)findViewById(R.id.btnstop);
murlPath = (EditText)findViewById(R.id.urlpath);
//String str="/mnt/sdcard/2.mp4"
murlPath.setText("/mnt/sdcard/2.mp4");
mvideoserface = (SurfaceView)findViewById(R.id.surfaceView1);
mplayerbtn.setOnClickListener(new ClickEvent());
mstopbtn.setOnClickListener(new ClickEvent());
surfaceHolder=mvideoserface.getHolder();
surfaceHolder.setFormat(PixelFormat.RGBX_8888);
surfaceHolder.addCallback(mSurfaceCallback);
try {
LibVLC.useIOMX(this);
mLibVLC = LibVLC.getInstance();
} catch (LibVlcException e) {
e.printStackTrace();
}
}
private SurfaceHolder.Callback mSurfaceCallback = new Callback() {
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
mLibVLC.attachSurface(holder.getSurface(), vlcplayerActivity.this, width, height);
}
public void surfaceCreated(SurfaceHolder holder) {
try {
} catch (Exception e) {
Log.e("mediaPlayer", "error", e);
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
mLibVLC.detachSurface();
}
};
public void setSurfaceSize(int width, int height) {
// store video size
mVideoHeight = height;
mVideoWidth = width;
Message msg = mHandler.obtainMessage(SURFACE_SIZE);
mHandler.sendMessage(msg);
}
/**
* Handle resize of the surface and the overlay
*/
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
/*case FADE_OUT:
hideOverlay(false);
break;
case SHOW_PROGRESS:
int pos = setOverlayProgress();
if (!mDragging && mShowing && mLibVLC.isPlaying()) {
msg = obtainMessage(SHOW_PROGRESS);
sendMessageDelayed(msg, 1000 - (pos % 1000));
}
break;*/
case SURFACE_SIZE:
changeSurfaceSize();
break;
/*case FADE_OUT_INFO:
if (mInfo.getVisibility() == View.VISIBLE)
mInfo.startAnimation(AnimationUtils.loadAnimation(
VideoPlayerActivity.this, android.R.anim.fade_out));
mInfo.setVisibility(View.INVISIBLE);*/
}
}
};
private void changeSurfaceSize() {
// get screen size
int dw = getWindowManager().getDefaultDisplay().getWidth();
int dh = getWindowManager().getDefaultDisplay().getHeight();
// calculate aspect ratio
double ar = (double) mVideoWidth / (double) mVideoHeight;
// calculate display aspect ratio
double dar = (double) dw / (double) dh;
switch (mCurrentSize) {
case SURFACE_BEST_FIT:
if (dar < ar)
dh = (int) (dw / ar);
else
dw = (int) (dh * ar);
break;
case SURFACE_FIT_HORIZONTAL:
dh = (int) (dw / ar);
break;
case SURFACE_FIT_VERTICAL:
dw = (int) (dh * ar);
break;
case SURFACE_FILL:
break;
case SURFACE_16_9:
ar = 16.0 / 9.0;
if (dar < ar)
dh = (int) (dw / ar);
else
dw = (int) (dh * ar);
break;
case SURFACE_4_3:
ar = 4.0 / 3.0;
if (dar < ar)
dh = (int) (dw / ar);
else
dw = (int) (dh * ar);
break;
case SURFACE_ORIGINAL:
dh = mVideoHeight;
dw = mVideoWidth;
break;
}
surfaceHolder.setFixedSize(mVideoWidth, mVideoHeight);
LayoutParams lp = mvideoserface.getLayoutParams();
lp.width = dw;
lp.height = dh;
mvideoserface.setLayoutParams(lp);
mvideoserface.invalidate();
}
}
- android平台调用vlc播放器的例子
- 【媒体应用:Android平台VLC媒体播放器探索之路系列】之一:VLC播放器开篇
- Qt调用VLC写的视频播放器源码
- 关于vlc播放器的ActiveX控件调用问题
- Android编译VLC播放器
- VLC Android播放器介绍
- Android VLC RTSP播放器
- Android使用VLC库开发自己的视频播放器
- 基于VLC框架的Android视频播放器Demo
- VLC视频播放器开发--VLC for Android编译
- VLC视频播放器开发--VLC for Android编译
- vlc-android 中调用用libvlcjni.so实现流媒体播放
- vlc-android 中调用用libvlcjni.so实现流媒体播放
- vlc-android 中调用用libvlcjni.so实现流媒体播放
- vlc-android 中调用用libvlcjni.so实现流媒体播放
- Android 如何调用vlc直接播放对应视频
- Android VLC播放器二次开发1
- android平台vlc对mms的支持
- ADC 驱动移植
- 区域性问题导致多语言软件运行出错
- 分类页面:repeater控件的应用
- 图像解析库使用范例
- 堆和栈的区别(转过无数次的文章)
- android平台调用vlc播放器的例子
- ini 文件操作
- 丢失grub的安装和修复 mbr 以及制作U盘安装grub
- android 常用对话框 ---转载
- Facestagram: 合体Instagram五个新特性YY
- PAFF 和MBAFF
- C#串口通信编程类(修改版)
- Jni中C++和Java的参数传递
- 鼠标滑过效果