Ejemplo n.º 1
0
        public void Dispose()
        {
            _cancel = true;

            if (_tracktorelease != IntPtr.Zero)
            {
                LibVLCWrapper.libvlc_media_tracks_release(_tracktorelease, _tracks);
            }

            if (_mediaPlayer != IntPtr.Zero)
            {
                LibVLCWrapper.libvlc_media_player_release(_mediaPlayer);
            }

            if (_media != IntPtr.Zero)
            {
                LibVLCWrapper.libvlc_media_release(_media);
            }

            if (_libvlc != IntPtr.Zero)
            {
                LibVLCWrapper.libvlc_release(_libvlc);
            }

            _mediaPlayer = IntPtr.Zero;
            _media       = IntPtr.Zero;
            _libvlc      = IntPtr.Zero;
        }
Ejemplo n.º 2
0
        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?");
            }
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        private libvlc_video_track_t?GetVideoTrack()
        {
            libvlc_video_track_t?vtrack = null;
            IntPtr p;
            int    tracks = LibVLCWrapper.libvlc_media_tracks_get(_media, out p);

            _tracks         = tracks;
            _tracktorelease = p;

            for (int i = 0; i < tracks; i++)
            {
                IntPtr mtrackptr            = Marshal.ReadIntPtr(p, i * IntPtr.Size);
                libvlc_media_track_t mtrack = Marshal.PtrToStructure <libvlc_media_track_t>(mtrackptr);
                if (mtrack.i_type == libvlc_track_type_t.libvlc_track_video)
                {
                    vtrack = Marshal.PtrToStructure <libvlc_video_track_t>(mtrack.media);
                }
            }

            return(vtrack);
        }