【问题标题】:Trouble formatting a path for the Linphone SDK in Swift在 Swift 中格式化 Linphone SDK 的路径时遇到问题
【发布时间】:2017-04-11 21:03:59
【问题描述】:

提前感谢您的帮助!

我正在尝试在 Mac OS 上使用 Swift 中的 Linphone SDK 记录通话,但在将路径传递给函数时遇到了问题:

func linphone_call_params_set_record_file(_ cp: OpaquePointer!, _ path: UnsafePointer<Int8>!)

正常工作(SDK 是用 C 编写的,尽管我使用 Swift 和 桥接头 访问它)。 Linphone SDK 工作正常,我可以通过编程方式拨打和接听电话,并提供完整的音频支持。

在尝试调用通话记录器时,我向此函数传递了一个路径(pathtofile),例如:

let pathtofile = "/Users/Alex/Safety/1.wav"

我想存储录音文件的位置。

func SafetyNetAVRecorderInitializer(pathtofile: String) -> Bool {
    // Convert pathtofile to UnsafePointer<Int8>.
    let cpathtofile = (pathtofile as NSString).utf8String
    let path = UnsafeMutablePointer<Int8>(mutating: cpathtofile)

    // Actually begin call recording.
    if currentcall != nil {
        let currentcallparameters = linphone_call_get_current_params(currentcall)
        linphone_call_params_set_record_file (currentcallparameters, path)
        linphone_call_start_recording(currentcall)
        return true
    }
    return false
}

linphone_call_params_set_record_file() 上没有遇到运行时错误,但是当我尝试调用linphone_call_start_recording() 时,录制没有开始,并且在控制台中打印了一个错误,内容如下:

ortp-error-linphone_call_start_recording():没有指定输出文件。使用 linphone_call_params_set_record_file()。

如何正确地将有效路径传递给linphone_call_params_set_record_file()?我尝试直接传递一个普通的 Swift String 而不是 UnsafePointer&lt;Int8&gt; 无济于事。我只是误解了 C 中路径的格式吗?

供参考,SDK方法来源为:

void linphone_call_params_set_record_file(LinphoneCallParams *cp, const char *path){
if (cp->record_file){
    ms_free(cp->record_file);
    cp->record_file=NULL;
}
if (path) cp->record_file=ms_strdup(path);
}

再次感谢!

【问题讨论】:

    标签: c swift macos linphone-sdk


    【解决方案1】:

    试试这个:

    let cpathtofile = (pathtofile as NSString).utf8String! // Unwraps!
    ...
    inphone_call_params_set_record_file(currentcallparameters, cpathtofile)
    

    【讨论】:

    • 很遗憾,这不起作用——不过,感谢您的帮助!
    • @kmypwn 你应该也可以directly pass pathtofile: String。也许您的错误在其他地方... :-(
    • 我怀疑是……希望对 Linphone SDK 有更深入了解的人可以提供一些见解。
    • 对于它的价值,这里是 SDK 函数 linphone_call_params_set_record_file(): void linphone_call_params_set_record_file(LinphoneCallParams *cp, const char *path){ if (cp-&gt;record_file){ ms_free(cp-&gt;record_file); cp-&gt;record_file=NULL; } if (path) cp-&gt;record_file=ms_strdup(path); }
    • @PauloMattos,谢谢这对我有用。但是我在播放记录文件时遇到了问题。目前它记录在 .mkv 文件中。你能推荐一种替代方法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-03
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多