private void TrackReaderThread() { int _trackGetAttempts = 0; while (_trackGetAttempts < 10 && _cancel == false) { libvlc_video_track_t?track = GetVideoTrack(); if (track.HasValue && track.Value.i_width > 0 && track.Value.i_height > 0) { _videoTrack = track; if (_width <= 0 || _height <= 0) { _width = (int)_videoTrack.Value.i_width; _height = (int)_videoTrack.Value.i_height; LibVLCWrapper.libvlc_video_set_format(_mediaPlayer, "RV24", _videoTrack.Value.i_width, _videoTrack.Value.i_height, (uint)_width * (uint)_channels); } break; } _trackGetAttempts++; System.Threading.Thread.Sleep(500); } if (_trackGetAttempts >= 10) { Debug.LogError("Maximum attempts of getting video track reached, maybe opening failed?"); } }
public VLCPlayer(int width, int height, string mediaUrl, bool audio) { Debug.Log("Playing: " + mediaUrl); _width = width; _height = height; _gcHandle = GCHandle.Alloc(this); string argstrings = _defaultArgs; if (!audio) { argstrings += ";--no-audio"; } string[] args = argstrings.Split(';'); _libvlc = LibVLCWrapper.libvlc_new(args.Length, args); if (_libvlc == IntPtr.Zero) { Debug.LogError("Failed loading new libvlc instance..."); return; } _media = LibVLCWrapper.libvlc_media_new_location(_libvlc, mediaUrl); if (_media == IntPtr.Zero) { Debug.LogError("For some reason media is null, maybe typo in the URL?"); return; } _mediaPlayer = LibVLCWrapper.libvlc_media_player_new(_libvlc); LibVLCWrapper.libvlc_media_player_set_media(_mediaPlayer, _media); _lockHandle = vlc_lock; _unlockHandle = vlc_unlock; _displayHandle = vlc_picture; LibVLCWrapper.libvlc_video_set_callbacks(_mediaPlayer, _lockHandle, _unlockHandle, _displayHandle, GCHandle.ToIntPtr(_gcHandle)); LibVLCWrapper.libvlc_video_set_format(_mediaPlayer, "RV24", (uint)_width, (uint)_height, (uint)_width * (uint)_channels); LibVLCWrapper.libvlc_media_player_play(_mediaPlayer); System.Threading.Thread t = new System.Threading.Thread(TrackReaderThread); t.Start(); }