集成
导入依赖jar
官方例子中的SmartPlayerJni
集成注意:该java必须处在com.daniulive.smartplayer包名下,否则init会出错。
public class SmartPlayerJni {
/**
* Initialize Player.
*
* @param ctx: get by this.getApplicationContext()
*
* <pre>This function must be called firstly.</pre>
*
* @return player handle if successful, if return 0, which means init failed.
*/
public native long SmartPlayerInit(Object ctx);
/**
* Set callback event
*
* @param callback function
*
* @return {0} if successful
*/
public native int SetSmartPlayerEventCallback(long handle, SmartEventCallback callback);
/**
* Set Video HW decoder, if support HW decoder, it will return 0
*
* @param isHWDecoder: 0: software decoder; 1: hardware decoder.
*
* @return {0} if successful
*/
public native int SetSmartPlayerVideoHWDecoder(long handle, int isHWDecoder);
/**
* Set Surface view.
*
* @param handle: return value from SmartPlayerInit()
*
* @param glSurface: surface view
*
* <pre> NOTE: if not set or set surface with null, it will playback audio only. </pre>
*
* @return {0} if successful
*/
public native int SmartPlayerSetSurface(long handle, Object surface);
/**
* Set External Render.
*
* @param handle: return value from SmartPlayerInit()
*
* @param external_render: External Render
*
* @return {0} if successful
*/
public native int SmartPlayerSetExternalRender(long handle, Object external_render);
/**
* Set AudioOutput Type
*
* @param handle: return value from SmartPlayerInit()
*
* @param use_audiotrack:
*
* <pre> NOTE: if use_audiotrack with 0: it will use auto-select output devices; if with 1: will use audiotrack mode. </pre>
*
* @return {0} if successful
*/
public native int SmartPlayerSetAudioOutputType(long handle, int use_audiotrack);
/**
* Set buffer
*
* @param handle: return value from SmartPlayerInit()
*
* @param buffer:
*
* <pre> NOTE: Unit is millisecond, range is 200-5000 ms </pre>
*
* @return {0} if successful
*/
public native int SmartPlayerSetBuffer(long handle, int buffer);
/**
* Set mute or not
*
* @param is_mute: if with 1:mute, if with 0: does not mute
*
* @return {0} if successful
*/
public native int SmartPlayerSetMute(long handle, int is_mute);
/**
* It's only used when playback RTSP stream
*
* Default with UDP mode
*
* @param isUsingTCP: if with 1, it will via TCP mode, while 0 with UDP mode
*
* @return {0} if successful
*/
public native int SmartPlayerSetRTSPTcpMode(long handle, int is_using_tcp);
/**
* Set playback orientation.
*
* @param handle: return value from SmartPlayerInit()
*
* @param surOrg: current orientation, PORTRAIT 1, LANDSCAPE with 2
*
* @return {0} if successful
*/
public native int SmartPlayerSetOrientation(long handle, int surOrg);
/**
* Start playback stream
*
* @param handle: return value from SmartPlayerInit()
*
* @param uri: playback uri
*
* @return {0} if successful
*/
public native int SmartPlayerStartPlayback(long handle, String uri);
/**
* Close player instance.
*
* @param handle: return value from SmartPlayerInit()
*
* <pre> NOTE: it could not use player handle after call this function. </pre>
*
* @return {0} if successful
*/
public native int SmartPlayerClose(long handle);
}
接收推流
public class SmartPlayer extends Activity {
private SurfaceView sSurfaceView = null;
private long playerHandle = 0;
private static final int PORTRAIT = 1; //竖屏
private static final int LANDSCAPE = 2; //横屏
private static final String TAG = "SmartPlayer";
private SmartPlayerJni libPlayer = null;
private int currentOrigentation = PORTRAIT;
private boolean isPlaybackViewStarted = false;
private String playbackUrl = null;
private boolean isMute = false;
private boolean isHardwareDecoder = false;
Button btnPopInputText;
Button btnPopInputUrl;
Button btnMute;
Button btnStartStopPlayback;
Button btnHardwareDecoder;
TextView txtCopyright;
TextView txtQQQun;
LinearLayout lLa