142 lines
4.0 KiB
Nim
142 lines
4.0 KiB
Nim
when defined(Windows):
|
|
const libName* = "libvlc.dll"
|
|
when defined(Linux):
|
|
const libName* = "libvlc.so"
|
|
when defined(MacOsX):
|
|
const libName* = "libvlc.dylib"
|
|
|
|
type
|
|
LibVlcInstance* = ptr object
|
|
VlcMediaPlayer* = ptr object
|
|
VlcMedia* = ptr object
|
|
|
|
VlcMetaType* = enum
|
|
vmTitle,
|
|
vmArtist,
|
|
vmGenre,
|
|
vmCopyright,
|
|
vmAlbum,
|
|
vmTrackNumber,
|
|
vmDescription,
|
|
vmRating,
|
|
vmDate,
|
|
vmSetting,
|
|
vmURL,
|
|
vmLanguage,
|
|
vmNowPlaying,
|
|
vmPublisher,
|
|
vmEncodedBy,
|
|
vmArtworkURL,
|
|
vmTrackID,
|
|
vmTrackTotal,
|
|
vmDirector,
|
|
vmSeason,
|
|
vmEpisode,
|
|
vmShowName,
|
|
vmActors,
|
|
vmAlbumArtist,
|
|
vmDiscNumber,
|
|
vmDiscTotal
|
|
|
|
VlcMediaState* = enum
|
|
vmsNothingSpecial,
|
|
vmsOpening,
|
|
vmsBuffering,
|
|
vmsPlaying,
|
|
vmsPaused,
|
|
vmsStopped,
|
|
vmsEnded,
|
|
vmsError
|
|
|
|
{.push dynlib: libName.}
|
|
|
|
# LibVlcCore
|
|
# https://videolan.videolan.me/vlc/group__libvlc__core.html
|
|
|
|
proc libvlc_new(argc: cint, argv: cstringArray):
|
|
LibVlcInstance {.importc: "libvlc_new".}
|
|
|
|
proc release*(inst: LibVlcInstance) {.importc: "libvlc_release".}
|
|
|
|
proc retain*(inst: LibVlcInstance) {.importc: "libvlc_retain".}
|
|
|
|
proc version*(inst: LibVlcInstance): cstring {.importc: "libvlc_get_version".}
|
|
|
|
# Media Player
|
|
# https://videolan.videolan.me/vlc/group__libvlc__media__player.html
|
|
proc newMediaPlayer*(inst: LibVlcInstance):
|
|
VlcMediaPlayer {.importc: "libvlc_media_player_new".}
|
|
|
|
proc release*(mp: VlcMediaPlayer) {.importc: "libvlc_media_player_release".}
|
|
|
|
proc retain*(mp: VlcMediaPlayer) {.importc: "libvlc_media_player_retain".}
|
|
|
|
proc setMedia*(mp: VlcMediaPlayer, m: VlcMedia):
|
|
void {.importc: "libvlc_media_player_set_media" }
|
|
|
|
proc getMedia*(mp: VlcMediaPlayer):
|
|
VlcMedia {.importc: "libvlc_media_player_get_media" }
|
|
|
|
proc libvlc_media_player_is_playing(mp: VlcMediaPlayer):
|
|
cint {.importc: "libvlc_media_player_is_playing".}
|
|
|
|
proc isPlaying*(mp: VlcMediaPlayer): bool =
|
|
libvlc_media_player_is_playing(mp) > 0
|
|
|
|
proc libvlc_media_player_play(mp: VlcMediaPlayer):
|
|
cint {.importc: "libvlc_media_player_play".}
|
|
|
|
proc play*(mp: VlcMediaPlayer): bool =
|
|
libvlc_media_player_play(mp) >= 0
|
|
|
|
proc libvlc_media_player_set_pause(mp: VlcMediaPlayer, pause: cint):
|
|
void {.importc: "libvlc_media_player_set_pause"}
|
|
|
|
proc setPause*(mp: VlcMediaPlayer, pause = true) =
|
|
if pause: mp.libvlc_media_player_set_pause(1)
|
|
else: mp.libvlc_media_player_set_pause(0)
|
|
|
|
proc togglePause*(mp: VlcMediaPlayer):
|
|
void {.importc: "libvlc_media_player_pause"}
|
|
|
|
proc stop*(mp: VlcMediaPlayer): void {.importc: "libvlc_media_player_stop"}
|
|
|
|
# Media
|
|
# https://videolan.videolan.me/vlc/group__libvlc__media.html
|
|
proc mediaFromUrl*(inst: LibVlcInstance, url: cstring):
|
|
VlcMedia {.importc: "libvlc_media_new_location".}
|
|
|
|
proc mediaFromPath*(inst: LibVlcInstance, path: cstring):
|
|
VlcMedia {.importc: "libvlc_media_new_location".}
|
|
|
|
proc retain*(media: VlcMedia) {.importc: "libvlc_media_retain".}
|
|
proc release*(media: VlcMedia) {.importc: "libvlc_media_release".}
|
|
|
|
proc duplicate*(media: VlcMedia): VlcMedia {.importc: "libvlc_media_duplicate".}
|
|
|
|
proc parse*(media: VlcMedia) {.importc: "libvlc_media_parse".}
|
|
proc isParsed*(media: VlcMedia) {.importc: "libvlc_media_is_parsed".}
|
|
|
|
proc getMeta*(media: VlcMedia, key: VlcMetaType):
|
|
cstring {.importc: "libvlc_media_get_meta".}
|
|
|
|
proc setMeta*(media: VlcMedia, key: VlcMetaType, value: cstring)
|
|
{.importc: "libvlc_media_set_meta".}
|
|
|
|
proc saveMeta*(media: VlcMedia): bool {.importc: "libvlc_media_save_meta".}
|
|
|
|
# Error
|
|
# https://videolan.videolan.me/vlc/group__libvlc__error.html
|
|
proc libvlc_errmsg*(): cstring {.importc: "libvlc_errmsg" .}
|
|
proc libvlc_clearerr*(): cstring {.importc: "libvlc_clearerr" .}
|
|
proc libvlc_printerr*(fmt: cstring): cstring {.importc: "libvlc_printerr" .}
|
|
|
|
# Nim-native wrappers
|
|
proc newVlc*(args: openarray[string] = []): LibVlcInstance =
|
|
let argc = args.len
|
|
let argv = allocCstringArray(args)
|
|
result = libvlc_new(cast[cint](argc), argv)
|
|
if result.isNil:
|
|
raise newException(Exception,
|
|
"Failed to initialize VLC instance: " & $libvlc_errmsg())
|