最近,好多开发者在unity3d平台面临一个问题,难于找到一个真正靠谱的低延迟rtmp播放器或rtsp播放器。
不少开发者联系我们,希望大牛直播SDK能出官方版的unity3d直播播放器SDK,以下是Android端的SDK接口:
///
/// Init
///
public int NT_U3D_Init()
{
return DANIULIVE_RETURN_OK;
}
///
/// 开始
/// 返回播放句柄
///
public long NT_U3D_Open()
{
if ( 0 != player_obj_.Call("Init", java_obj_cur_activity_) )
{
return 0;
}
return player_obj_.Call("Open");
}
///
/// Register Game Object,用于消息传递
///
public int NT_U3D_Set_Game_Object(long handle, string gameObjectName)
{
return player_obj_.Call("SetGameObject", handle, gameObjectName);
}
///
/// 设置解码方式 false 软件解码 true 硬件解码 默认为false
///
///
public int NT_U3D_SetVideoDecoderMode(long handle, int isHwDecoder)
{
return player_obj_.Call("SetPlayerVideoHWDecoder", handle, isHwDecoder);
}
///
/// 设置音频输出模式: if 0: 自动选择; if with 1: audiotrack模式
///
///
public int NT_U3D_SetAudioOutputType(long handle, int use_audiotrack)
{
return player_obj_.Call("SetAudioOutputType", handle, use_audiotrack);
}
///
/// 设置播放端缓存大小, 默认200毫秒
///
///
public int NT_U3D_SetBuffer(long handle, int buffer)
{
return player_obj_.Call("SetBuffer", handle, buffer);
}
///
/// 接口可实时调用:设置是否实时静音,1:静音; 0: 取消静音
///
///
public int NT_U3D_SetMute(long handle, int is_mute)
{
return player_obj_.Call("SetMute", handle, is_mute);
}
///
/// 设置RTSP TCP模式, 1: TCP; 0: UDP
///
///
public int NT_U3D_SetRTSPTcpMode(long handle, int is_using_tcp)
{
return player_obj_.Call("SetRTSPTcpMode", handle, is_using_tcp);
}
///
/// 设置超低延迟模式 false不开启 true开启 默认false
///
///
public int NT_U3D_SetPlayerLowLatencyMode(long handle, int mode)
{
return player_obj_.Call("SetPlayerLowLatencyMode", handle, mode);
}
///
/// 设置是否回调下载速度
/// is_report: if 1: 上报下载速度, 0: 不上报.
/// report_interval: 上报间隔,以秒为单位,>0.
///
///
///
public int NT_U3D_SetReportDownloadSpeed(long handle, int is_report, int report_interval)
{
return player_obj_.Call("SetReportDownloadSpeed", handle, is_report, report_interval);
}
///
/// 设置是否需要在播放或录像过程中快照
///
///
public int NT_U3D_SetSaveImageFlag(long handle, int is_save_image)
{
return player_obj_.Call("SetSaveImageFlag", handle, is_save_image);
}
///
/// 播放或录像过程中快照
///
///
public int NT_U3D_SaveCurImage(long handle, string imageName)
{
return player_obj_.Call("SaveCurImage", handle, imageName);
}
///
/// 播放或录像过程中,快速切换url
///
///
public int NT_U3D_SwitchPlaybackUrl(long handle, string uri)
{
return player_obj_.Call("SwitchPlaybackUrl", handle, uri);
}
///
/// 创建录像存储路径
///
///
public int NT_U3D_CreateFileDirectory(string path)
{
return player_obj_.Call("CreateFileDirectory", path);
}
///
/// 设置录像存储路径
///
///
public int NT_U3D_SetRecorderDirectory(long handle, string path)
{
return player_obj_.Call("SetRecorderDirectory", handle, path);
}
///
/// 设置单个录像文件大小
///
///
public int NT_U3D_SetRecorderFileMaxSize(long handle, int size)
{
return player_obj_.Call("SetRecorderFileMaxSize", handle, size);
}
///
/// 设置播放路径
///
public int NT_U3D_SetUrl(long handle, string url)
{
return player_obj_.Call("SetUrl", handle, url);
}
///
/// 开始播放
///
public int NT_U3D_StartPlay(long handle)
{
return player_obj_.Call("StartPlay", handle);
}
///
/// 获取YUV数据
///
public AndroidJavaObject NT_U3D_GetVideoFrame(long handle)
{
return player_obj_.Call("GetVideoFrame", handle);
}
///
/// 停止播放
///
public int NT_U3D_StopPlay(long handle)
{
return player_obj_.Call("StopPlay", handle);
}
///
/// 开始录像
///
public int NT_U3D_StartRecorder(long handle)
{
return player_obj_.Call("StartRecorder", handle);
}
///
/// 停止录像
///
public int NT_U3D_StopRecorder(long handle)
{
return player_obj_.Call("StopRecorder", handle);
}
///
/// 关闭播放
///
public int NT_U3D_Close(long handle)
{
return player_obj_.Call("Close", handle);
}
///
/// UnInit Player
///
public int NT_U3D_UnInit()
{
return DANIULIVE_RETURN_OK;
}
经测试,Android/iOS端效果如下,播放端延迟低于1秒,也可能是unity3d平台下最快最稳定的rtmp播放器/rtsp播放器:
视频效果图:
点击播放视频
Unity3D-Android播放端APK下载
android/iOS播放器SDK(V2)Unity3D调用说明
更多资料,可以访问 https://github.com/daniulive/SmarterStreaming