示例#1
0
        /// <summary>
        /// Initializes previously preparsed next media to play.
        /// </summary>
        /// <param name="preparsedMedia">
        /// A <see cref="PreparsedMedia"/> instance returned from <see cref="ParseMediaInput"/> method.
        /// </param>
        public override void SetNextMediaInput(PreparsedMedia preparsedMedia)
        {
            VerifyObjectIsNotDisposed();
            //
            if (preparsedMedia == null)
            {
                throw new ArgumentNullException("mediaInput");
            }
            //
            nextMedia = preparsedMedia.MediaInput;
            // precreating of libvlc media
            if (currentMediaInternal != currentMediaInternalPreprepared)
            {
                if (nextMediaInternalPreprepared != null)
                {
                    nextMediaInternalPreprepared.Dispose();
                    nextMediaInternalPreprepared = null;
                }
            }
            VlcMediaInternal media = GetPreparsedMediaInternal(preparsedMedia);

            media.SetOutput(playerOutput);
            //
            nextMediaInternalPreprepared = media;
            disposeNextMediaPreprepared  = true;
        }
示例#2
0
 /// <summary>
 /// Stops player and cleans up resources.
 /// </summary>
 protected override void Dispose(bool isDisposing)
 {
     try {
         if (isDisposing)
         {
             // Suppress exceptions in Dispose()
             try {
                 stop();
             } catch (VlcTimeoutException exc) {
                 if (logger.IsErrorEnabled)
                 {
                     logger.Error("Timeout while stopping player in Dispose() method.", exc);
                 }
             }
             //
             if (internalPlayer != null)
             {
                 internalPlayer.Dispose();
             }
             if (currentMediaInternal != null && disposeCurrentMedia)
             {
                 currentMediaInternal.Dispose();
                 currentMediaInternal = null;
             }
             //
             if (stateChangeEventHandle != null)
             {
                 stateChangeEventHandle.Close();
             }
         }
     } finally {
         base.Dispose(isDisposing);
     }
 }
示例#3
0
        /// <summary>
        /// Parses media and returns information about it.
        /// </summary>
        /// <param name="mediaInput">
        /// A <see cref="MediaInput"/> to locate media to be preparsed.
        /// </param>
        /// <returns>
        /// A <see cref="PreparsedMedia"/> instance with information about media located using
        /// <param cref="mediaInput"/>.
        /// </returns>
        public override PreparsedMedia ParseMediaInput(MediaInput mediaInput)
        {
            VlcMediaInternal media = internalObjectsFactory.CreateVlcMediaInternal(mediaInput);

            media.Parse();
            return(new VlcPreparsedMedia(mediaInput, media));
        }
示例#4
0
 private void stop()
 {
     if (currentMediaInternal != null)
     {
         try {
             if ((currentMediaInternal.State != VlcMediaState.Ended) &&
                 (currentMediaInternal.State != VlcMediaState.NothingSpecial))
             {
                 //
                 internalPlayer.Stop();
                 waitForStateChangeOrFail(VlcMediaState.Stopped);
             }
         } finally {
             if (disposeCurrentMedia)
             {
                 currentMediaInternal.Dispose();
                 currentMediaInternal = null;
             }
         }
     }
 }
示例#5
0
 /// <summary>
 /// Specifies next media input.
 /// </summary>
 public override void SetNextMediaInput(MediaInput mediaInput)
 {
     VerifyObjectIsNotDisposed();
     //
     if (mediaInput == null)
     {
         throw new ArgumentNullException("mediaInput");
     }
     //
     nextMedia = mediaInput;
     // precreating of libvlc media
     if (currentMediaInternal != currentMediaInternalPreprepared)
     {
         if (nextMediaInternalPreprepared != null)
         {
             nextMediaInternalPreprepared.Dispose();
             nextMediaInternalPreprepared = null;
         }
     }
     nextMediaInternalPreprepared = internalObjectsFactory.CreateVlcMediaInternal(nextMedia);
     nextMediaInternalPreprepared.SetOutput(playerOutput);
     disposeNextMediaPreprepared = true;
 }
示例#6
0
            public VlcPreparsedMedia(Io.MediaInput mediaInput, VlcMediaInternal media) : base(mediaInput)
            {
                if (media == null)
                {
                    throw new ArgumentNullException("media");
                }
                this.media    = media;
                this.Duration = media.Duration;
                //
                List <AudioTrackInfo> audioTracks = new List <AudioTrackInfo>();
                List <VideoTrackInfo> videoTracks = new List <VideoTrackInfo>();

                libvlc_media_track_info_t[] tracks = media.GetTracksInfo();
                foreach (libvlc_media_track_info_t track in tracks)
                {
                    if (track.i_type == libvlc_track_t.libvlc_track_audio)
                    {
                        AudioTrackInfo audioTrack = new AudioTrackInfo();
                        audioTrack.BitRate     = track.i_rate;
                        audioTrack.Channels    = (int)Math.Min(track.i_channels, (uint)int.MaxValue);
                        audioTrack.Code        = track.i_codec;
                        audioTrack.Description = LibVlcInterop.vlc_fourcc_GetDescription(0, track.i_codec);
                        audioTracks.Add(audioTrack);
                    }
                    else if (track.i_type == libvlc_track_t.libvlc_track_video)
                    {
                        VideoTrackInfo videoTrack = new VideoTrackInfo();
                        videoTrack.Code        = track.i_codec;
                        videoTrack.Description = LibVlcInterop.vlc_fourcc_GetDescription(0, track.i_codec);
                        videoTrack.Height      = (int)Math.Min((uint)int.MaxValue, (uint)track.i_height);
                        videoTrack.Width       = (int)Math.Min((uint)int.MaxValue, (uint)track.i_width);
                        videoTracks.Add(videoTrack);
                    }
                }
                //
                SetTracksInfo(videoTracks, audioTracks);
            }
示例#7
0
        /// <summary>
        /// Internal.
        /// </summary>
        protected override void PlayNextInternal()
        {
            if (nextMedia == null)
            {
                throw new MediaPlayerException("Next media is not selected.");
            }
            // Verify nexyMedia
            if (nextMedia.Type == MediaInputType.File)
            {
                if (!File.Exists(nextMedia.Source))
                {
                    throw new FileNotFoundException("File of media specified was not found.", nextMedia.Source);
                }
            }
            //
            VlcMediaPlayerInternal mediaplayer = internalPlayer;
            // create nextMediaInternal and start playing
            VlcMediaInternal nextMediaInternal = nextMediaInternalPreprepared;

            nextMediaInternalPreprepared = null;
            //
            nextMediaInternal.SetOutput(playerOutput);
            mediaplayer.SetMedia(nextMediaInternal);
            if (playerOutput.IsWindowDefined)
            {
                if (playerOutput.Window != null && playerOutput.Window is DoubleWindowBase)
                {
                    // support old code
                    internalPlayer.SetDisplayOutputHwnd(((DoubleWindowBase)playerOutput.Window).GetActiveWindowHandleInternal());
                }
                else if (playerOutput.NativeWindow != null && playerOutput.NativeWindow is VlcNativeMediaWindow)
                {
                    // this will tell what to method we should call to initialize window
                    VlcNativeMediaWindow window = (VlcNativeMediaWindow)playerOutput.NativeWindow;
                    if (window.WindowType == VlcWindowType.HWND)
                    {
                        internalPlayer.SetDisplayOutputHwnd(window.NativeWindowHandle);
                    }
                    else if (window.WindowType == VlcWindowType.NSObject)
                    {
                        internalPlayer.SetDisplayOutputNSObject(window.NativeWindowHandle);
                    }
                    else if (window.WindowType == VlcWindowType.XWindow)
                    {
                        internalPlayer.SetDisplayOutputXWindow(window.NativeWindowHandle);
                    }
                    else if (window.WindowType == VlcWindowType.Agl)
                    {
                        internalPlayer.SetDisplayOutputAgl(window.NativeWindowHandle);
                    }
                }
            }
            //
            if (currentMediaInternal != null && disposeCurrentMedia)
            {
                currentMediaInternal.Dispose();
                currentMediaInternal = null;
            }
            //
            currentMediaInternal = nextMediaInternal;
            disposeCurrentMedia  = disposeNextMediaPreprepared;
            //
            startPlaying();
        }
示例#8
0
 /// <summary>
 /// Starts playing of media which was initialized using <see cref="SetMediaInput"/> method.
 /// If some media is playing now it will be simply restarted.
 /// </summary>
 protected override void PlayInternal()
 {
     if (currentMedia == null)
     {
         throw new MediaPlayerException("Current media is null.");
     }
     if (playerOutput == null)
     {
         throw new MediaPlayerException("Player output is null.");
     }
     //
     if (currentMediaInternal != null)
     {
         if (currentMediaInternal.State == VlcMediaState.Paused)
         {
             Resume();
             return;
         }
         if (currentMediaInternal.State == VlcMediaState.Playing)
         {
             Position = 0f;
             return;
         }
         Stop();
     }
     // Verify currentMedia
     if (currentMedia.Type == MediaInputType.File)
     {
         if (!File.Exists(currentMedia.Source))
         {
             throw new FileNotFoundException("File of media specified was not found.", currentMedia.Source);
         }
     }
     if (currentMediaInternalPreprepared == null)
     {
         currentMediaInternalPreprepared = internalObjectsFactory.CreateVlcMediaInternal(currentMedia);
         currentMediaInternalPreprepared.SetOutput(playerOutput);
     }
     //
     currentMediaInternal            = currentMediaInternalPreprepared;
     currentMediaInternalPreprepared = null;
     disposeCurrentMedia             = disposeCurrentMediaPreprepared;
     //
     internalPlayer.SetMedia(currentMediaInternal);
     if (playerOutput.IsWindowDefined)
     {
         if (playerOutput.Window != null && playerOutput.Window is DoubleWindowBase)
         {
             // support old code
             internalPlayer.SetDisplayOutputHwnd(((DoubleWindowBase)playerOutput.Window).GetActiveWindowHandleInternal());
         }
         else if (playerOutput.NativeWindow != null && playerOutput.NativeWindow is VlcNativeMediaWindow)
         {
             // this will tell what to method we should call to initialize window
             VlcNativeMediaWindow window = (VlcNativeMediaWindow)playerOutput.NativeWindow;
             if (window.WindowType == VlcWindowType.HWND)
             {
                 internalPlayer.SetDisplayOutputHwnd(window.NativeWindowHandle);
             }
             else if (window.WindowType == VlcWindowType.NSObject)
             {
                 internalPlayer.SetDisplayOutputNSObject(window.NativeWindowHandle);
             }
             else if (window.WindowType == VlcWindowType.XWindow)
             {
                 internalPlayer.SetDisplayOutputXWindow(window.NativeWindowHandle);
             }
             else if (window.WindowType == VlcWindowType.Agl)
             {
                 internalPlayer.SetDisplayOutputAgl(window.NativeWindowHandle);
             }
         }
     }
     //
     startPlaying();
 }