1. 程式人生 > >[Android]大牛直播SDK基於unity3d平臺的rtmp/rtsp直播播放端SDK介面說明

[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>
    /// 設定是否回撥下載速度
    /// 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/iOS端效果如下,播放端延遲低於1秒,也可能是unity3d平臺下最快最穩定的rtmp播放器/rtsp播放器:

視訊效果圖: