Unified · Split
| @@ -168,43 +168,6 @@ class LibmpvHelper { · 167 unmodified lines | |||
| 168 | } | 168 | } |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | func commandAsync(_ cmd: [String?], id: UInt64 = 1) { | ||
| 172 | if mpvHandle == nil { return } | ||
| 173 | var mCmd = cmd | ||
| 174 | mCmd.append(nil) | ||
| 175 | var cargs = mCmd.map { $0.flatMap { UnsafePointer<Int8>(strdup($0)) } } | ||
| 176 | mpv_command_async(mpvHandle, id, &cargs) | ||
| 177 | for ptr in cargs { free(UnsafeMutablePointer(mutating: ptr)) } | ||
| 178 | } | ||
| 179 | |||
| 180 | // Unsafe function when called while using the render API | ||
| 181 | func command(_ cmd: String) { | ||
| 182 | if mpvHandle == nil { return } | ||
| 183 | mpv_command_string(mpvHandle, cmd) | ||
| 184 | } | ||
| 185 | |||
| 186 | func getBoolProperty(_ name: String) -> Bool { | ||
| 187 | if mpvHandle == nil { return false } | ||
| 188 | var value = Int32() | ||
| 189 | mpv_get_property(mpvHandle, name, MPV_FORMAT_FLAG, &value) | ||
| 190 | return value > 0 | ||
| 191 | } | ||
| 192 | |||
| 193 | func getIntProperty(_ name: String) -> Int { | ||
| 194 | if mpvHandle == nil { return 0 } | ||
| 195 | var value = Int64() | ||
| 196 | mpv_get_property(mpvHandle, name, MPV_FORMAT_INT64, &value) | ||
| 197 | return Int(value) | ||
| 198 | } | ||
| 199 | |||
| 200 | func getStringProperty(_ name: String) -> String? { | ||
| 201 | guard let mpv = mpvHandle else { return nil } | ||
| 202 | guard let value = mpv_get_property_string(mpv, name) else { return nil } | ||
| 203 | let str = String(cString: value) | ||
| 204 | mpv_free(value) | ||
| 205 | return str | ||
| 206 | } | ||
| 207 | |||
| 208 | func deinitRender() { | 171 | func deinitRender() { |
| 209 | mpv_render_context_set_update_callback(mpvRenderContext, nil, nil) | 172 | mpv_render_context_set_update_callback(mpvRenderContext, nil, nil) |
| 210 | mp_render_context_set_control_callback(mpvRenderContext, nil, nil) | 173 | mp_render_context_set_control_callback(mpvRenderContext, nil, nil) |