Postby truekbcl » 10 Sep 2020 08:06
void play(const string & file)
{
const har * par[] = {
"--no-osd",
"--verbose=2",
};
int count = sizeof(par) / sizeof(char*);
_vlc = libvlc_new(count, par);
_player = libvlc_media_player_new(_vlc);
_dx11_render.crete();
libvlc_video_set_output_callbacks(
_player,
libvlc_video_engine_d3d11,
Setup_cb,
Cleanup_cb
Resize_cb,
UpdateOutput_cb,
Swap_cb,
StartRendering_cb,
nullptr,
nullptr,
SelectPlane_cb,
this);
// event manager
libvlc_event_manager_t *vlc_evt_man = libvlc_media_player_event_manager(_player);
libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerPlaying, on_vlc_event, this);
libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerEndReached, on_vlc_event, this);
string fs = string("file:///") + file;
libvlc_media_t * lm = libvlc_media_new_location(_vlc, fs.c_str());
libvlc_media_player_set_media(_player, _media);
libvlc_media_player_play(_player)
}
The above is my code.
I found a solution. If you call seek after switching the audio track, it can be played normally. But with libvlc_media_new_location, seek is very slow.
I tested the executable versions of 3.0 and 4.0 to play the same video, 3.0seek is fast, and 4.0 is very slow.
I switched to my own way of reading and writing files, that is, calling the libvlc_media_new_callbacks method, then the problem of slow seek is solved.
I guess that if you call libvlc_media_new_path, seek may be faster. But not sure.
I looked at the source code and found that the seek event was also sent when the audio track was changed, but for some reason, the playback became unsmooth.
Another problem is that when playing mpg files, the screen will always flash.