[Android]大牛直播SDK基于unity3d平台的rtmp/rtsp直播播放端SDK接口说明

最近,好多开发者在unity3d平台面临一个问题,难于找到一个真正靠谱的低延迟rtmp播放器或rtsp播放器。

不少开发者联系我们,希望大牛直播SDK能出官方版的unity3d直播播放器SDK,以下是Android端的SDK接口:


    /// <summary>
    /// Init
    /// </summary>
    public int NT_U3D_Init()
    {
        return DANIULIVE_RETURN_OK;
    }

    /// <summary>
    /// 开始
    /// 返回播放句柄
    /// </summary>
    public long NT_U3D_Open()
    {
        if ( 0 != player_obj_.Call<int>("Init", java_obj_cur_activity_) )
        {
            return 0;
        }

        return player_obj_.Call<long>("Open");
    }

    /// <summary>
    /// Register Game Object,用于消息传递
    /// </summary>
    public int NT_U3D_Set_Game_Object(long handle, string gameObjectName)
    {
        return player_obj_.Call<int>("SetGameObject", handle, gameObjectName);
    }

    /// <summary>
    /// 设置解码方式 false 软件解码 true 硬件解码 默认为false
    /// </summary>
    /// <param name="isHwDecoder"></param>
    public int NT_U3D_SetVideoDecoderMode(long handle, int isHwDecoder)
    {
        return player_obj_.Call<int>("SetPlayerVideoHWDecoder", handle, isHwDecoder);
    }

    /// <summary>
    /// 设置音频输出模式: if 0: 自动选择; if with 1: audiotrack模式
    /// </summary>
    /// <param name="use_audiotrack"></param>
    public int NT_U3D_SetAudioOutputType(long handle, int use_audiotrack)
    {
        return player_obj_.Call<int>("SetAudioOutputType", handle, use_audiotrack);
    }

    /// <summary>
    /// 设置播放端缓存大小, 默认200毫秒
    /// </summary>
    /// <param name="buffer"></param>
    public int NT_U3D_SetBuffer(long handle, int buffer)
    {
        return player_obj_.Call<int>("SetBuffer", handle, buffer);
    }

    /// <summary>
    /// 接口可实时调用:设置是否实时静音,1:静音; 0: 取消静音
    /// </summary>
    /// <param name="is_mute"></param>
    public int NT_U3D_SetMute(long handle, int is_mute)
    {
        return player_obj_.Call<int>("SetMute", handle, is_mute);
    }

    /// <summary>
    /// 设置RTSP TCP模式, 1: TCP; 0: UDP
    /// </summary>
    /// <param name="is_using_tcp"></param>
    public int NT_U3D_SetRTSPTcpMode(long handle, int is_using_tcp)
    {
        return player_obj_.Call<int>("SetRTSPTcpMode", handle, is_using_tcp);
    }

    /// <summary>
    /// 设置超低延迟模式 false不开启 true开启 默认false
    /// </summary>
    /// <param name="mode"></param>
    public int NT_U3D_SetPlayerLowLatencyMode(long handle, int mode)
    {
        return player_obj_.Call<int>("SetPlayerLowLatencyMode", handle, mode);
    }

    /// <summary>
    /// 设置顺时针旋转, 注意除了0度之外, 其他角度都会额外消耗性能
    /// degress: 当前支持 0度,90度, 180度, 270度 旋转
    /// </summary>
    /// <param name="degress"></param>
    public int NT_U3D_SetRotation(long handle, int degress)
    {
        return player_obj_.Call<int>("SetRotation", handle, degress);
    }

    /// <summary>
    /// 设置是否回调下载速度
    /// is_report: if 1: 上报下载速度, 0: 不上报.
    /// report_interval: 上报间隔,以秒为单位,>0.
    /// </summary>
    /// <param name="is_report"></param>
    /// <param name="report_interval"></param>
    public int NT_U3D_SetReportDownloadSpeed(long handle, int is_report, int report_interval)
    {
        return player_obj_.Call<int>("SetReportDownloadSpeed", handle, is_report, report_interval);
    }

    /// <summary>
    /// 设置是否需要在播放或录像过程中快照
    /// </summary>
    /// <param name="is_save_image"></param>
    public int NT_U3D_SetSaveImageFlag(long handle, int is_save_image)
    {
        return player_obj_.Call<int>("SetSaveImageFlag", handle, is_save_image);
    }

    /// <summary>
    /// 播放或录像过程中快照
    /// </summary>
    /// <param name="imageName"></param>
    public int NT_U3D_SaveCurImage(long handle, string imageName)
    {
        return player_obj_.Call<int>("SaveCurImage", handle, imageName);
    }

    /// <summary>
    /// 播放或录像过程中,快速切换url
    /// </summary>
    /// <param name="uri"></param>
    public int NT_U3D_SwitchPlaybackUrl(long handle, string uri)
    {
        return player_obj_.Call<int>("SwitchPlaybackUrl", handle, uri);
    }

    /// <summary>
    /// 创建录像存储路径
    /// </summary>
    /// <param name="path"></param>
    public int NT_U3D_CreateFileDirectory(string path)
    {
        return player_obj_.Call<int>("CreateFileDirectory", path);
    }

    /// <summary>
    /// 设置录像存储路径
    /// </summary>
    /// <param name="path"></param>
    public int NT_U3D_SetRecorderDirectory(long handle, string path)
    {
        return player_obj_.Call<int>("SetRecorderDirectory", handle, path);
    }

    /// <summary>
    /// 设置单个录像文件大小
    /// </summary>
    /// <param name="size"></param>
    public int NT_U3D_SetRecorderFileMaxSize(long handle, int size)
    {
        return player_obj_.Call<int>("SetRecorderFileMaxSize", handle, size);
    }

    /// <summary>
    /// 设置播放路径
    /// </summary>
    public int NT_U3D_SetUrl(long handle, string url)
    {
        return player_obj_.Call<int>("SetUrl", handle, url);
    }

    /// <summary>
    /// 开始播放
    /// </summary>
    public int NT_U3D_StartPlay(long handle)
    {
        return player_obj_.Call<int>("StartPlay", handle);
    }

    /// <summary>
    /// 获取YUV数据
    /// </summary>
    public AndroidJavaObject NT_U3D_GetVideoFrame(long handle)
    {
        return player_obj_.Call<AndroidJavaObject>("GetVideoFrame", handle);
    }

    /// <summary>
    /// 停止播放
    /// </summary>
    public int NT_U3D_StopPlay(long handle)
    {
        return player_obj_.Call<int>("StopPlay", handle);
    }

    /// <summary>
    /// 开始录像
    /// </summary>
    public int NT_U3D_StartRecorder(long handle)
    {
        return player_obj_.Call<int>("StartRecorder", handle);
    }

    /// <summary>
    /// 停止录像
    /// </summary>
    public int NT_U3D_StopRecorder(long handle)
    {
        return player_obj_.Call<int>("StopRecorder", handle);
    }

    /// <summary>
    /// 关闭播放
    /// </summary>
    public int NT_U3D_Close(long handle)
    {
        return player_obj_.Call<int>("Close", handle);
    }

    /// <summary>
    /// UnInit Player
    /// </summary>
    public int NT_U3D_UnInit()
    {
        return DANIULIVE_RETURN_OK;
    }


经测试,Android端效果如下,播放端延迟低于1秒,也可能是unity3d平台下最快最稳定的rtmp播放器/rtsp播放器:

以下是大牛直播SDK的Android和iOS播放效果展示:


https://www.zhihu.com/video/985166276611915776


android/iOS播放器SDK(V2)Unity3D调用说明web1712221406366.gz01.bdysite.com

Unity3D-Android播放端APK下载

更多资料或索取Demo,可以访问官网 http://daniulive.comgithub.com/daniulive/Sm

编辑于 2018-05-30