예제 #1
0
 public void SetMedia(VlcMediaInternal media)
 {
     if (media == null)
     {
         throw new ArgumentNullException("media");
     }
     //
     VerifyObjectIsNotDisposed();
     //
     LibVlcInterop.libvlc_media_player_set_media(descriptor, media.Descriptor);
 }
예제 #2
0
        public void SetMedia(VlcMediaInternal media)
        {
            if (media == null)
            {
                throw new ArgumentNullException("media");
            }
            //
            VerifyObjectIsNotDisposed();
            //
            libvlc_exception_t exc = new libvlc_exception_t();

            LibVlcInterop.libvlc_exception_init(ref exc);
            LibVlcInterop.libvlc_media_player_set_media(descriptor, media.Descriptor, ref exc);
            if (exc.b_raised != 0)
            {
                throw new VlcInternalException(exc.Message);
            }
        }
 public void SetMedia(VlcMediaInternal media) {
     if (media == null) {
         throw new ArgumentNullException("media");
     }
     //
     VerifyObjectIsNotDisposed();
     //
     libvlc_exception_t exc = new libvlc_exception_t();
     LibVlcInterop.libvlc_exception_init(ref exc);
     LibVlcInterop.libvlc_media_player_set_media(descriptor, media.Descriptor, ref exc);
     if (exc.b_raised != 0) {
         throw new VlcInternalException(exc.Message);
     }
 }
예제 #4
0
 /// <summary>
 /// Specifies next media input.
 /// </summary>
 public override void SetNextMediaInput(MediaInput mediaInput) {
     VerifyObjectIsNotDisposed();
     //
     if (mediaInput == null) {
         throw new ArgumentNullException("mediaInput");
     }
     //
     nextMedia = mediaInput;
     // If nextMediaInternal was prepared to playing already we have to release it
     if (nextMediaInternal != null) {
         getNextMediaPlayerInternal().Stop();
         nextMediaInternal.Dispose();
         nextMediaInternal = null;
     }
     // If current player state is PLAYING we can prepare the nextMedia
     if (currentMediaInternal != null) {
         if ((currentMediaInternal.State == VlcMediaState.PLAYING) ||
             (currentMediaInternal.State == VlcMediaState.PAUSED)) {
             prepareNextMedia();
         }
     }
 }
예제 #5
0
 /// <summary>
 /// Begining playing media by mediaplayer, using current filter settings.
 /// </summary>
 private void startPlaying(VlcMediaPlayerInternal mediaplayer, VlcMediaInternal media) {
     if (logger.IsTraceEnabled) {
         logger.Trace("startPlaying method called.");
     }
     // Dump VLC Objects before start playing
     if (logger.IsTraceEnabled) {
         logger.Trace("DUMP before start playing :");
         logger.Trace(getVlcObjectsTreeDump());
     }
     List<int> loadedFiltersIdList = new List<int>();
     //
     libvlc_instance_t libvlc_instance = internalObjectsFactory.GetInteropStructure();
     getVlcObjectsByName(libvlc_instance.p_libvlc_int, ADJUST_FILTER_ALIAS, loadedFiltersIdList);
     //
     mediaplayer.Play();
     if (logger.IsTraceEnabled) {
         logger.Trace("mediaPlayer.Play() called.");
     }
     // Wait for PLAYING state. Otherwise the next call Pause() will take no effect
     waitForMediaState(media, VlcMediaState.PLAYING);
     if (logger.IsTraceEnabled) {
         logger.Trace("VlcMediaState is PLAYING now.");
     }
     // Dump VLC Objects after start playing
     if (logger.IsTraceEnabled) {
         logger.Trace("DUMP after star playing :");
         logger.Trace(getVlcObjectsTreeDump());
     }
     // If other thread is processing filters now, stop them and wait until it stopped
     stopWaitingFiltersThread();
     //
     currentMediaFilterAvailable = false;
     // Starting new thread for waiting filters
     if (logger.IsTraceEnabled) {
         logger.Trace("Starting new thread for waiting IAdjustable filter.");
     }
     //
     waitingFiltersThread = new Thread(waitingFiltersThreadHandler);
     waitingFiltersThread.Start(new VlcObjectsSnapshot(loadedFiltersIdList, libvlc_instance));
 }
예제 #6
0
 private void prepareNextMedia() {
     // If nextMedia was already loaded we need to release it before reinitialization.
     if (nextMediaInternal != null) {
         getNextMediaPlayerInternal().Stop();
         //
         nextMediaInternal.Dispose();
         nextMediaInternal = null;
     }
     //
     nextMediaInternal = internalObjectsFactory.CreateVlcMediaInternal(nextMedia);
     nextMediaInternal.SetOutput(playerOutput);
     //
     getNextMediaPlayerInternal().SetMedia(nextMediaInternal);
     getNextMediaPlayerInternal().SetDisplayOutput(
         (int) ((DoubleWindowBase) playerOutput.Window).GetInactiveWindowHandleInternal());
     //
     startPlaying(getNextMediaPlayerInternal(), nextMediaInternal);
     getNextMediaPlayerInternal().Pause();
     //
     waitForMediaState(nextMediaInternal, VlcMediaState.PAUSED);
     //
     if (nextMediaInternal.State != VlcMediaState.PAUSED) {
         throw new VlcTimeoutException("Timeout waiting required state.");
     }
 }
예제 #7
0
 /// <summary>
 /// Waiting for change the state of <paramref name="mediaInternal"/> to the requested <paramref name="stateRequired"/>.
 /// <see cref="MediaPlayerException"/> exception will be thrown if operation will be timeouted.
 /// </summary>
 private void waitForMediaState(VlcMediaInternal mediaInternal, VlcMediaState stateRequired) {
     if (mediaInternal == null) {
         throw new ArgumentNullException("mediaInternal");
     }
     //
     Stopwatch watch = timeoutWatch;
     try {
         TimeSpan timeout;
         lock (filtersWaitingThreadLock) {
             timeout = waitingRequiredStateTimeout;
         }
         //
         while (mediaInternal.State != stateRequired) {
             if (!watch.IsRunning) {
                 watch.Start();
             }
             if (watch.Elapsed > timeout) {
                 throw new VlcTimeoutException("Timeout waiting required state.");
             }
         }
     } finally {
         watch.Stop();
         watch.Reset();
     }
 }
예제 #8
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 (firstMediaPlayerInternal != null) {
                 firstMediaPlayerInternal.Dispose();
             }
             if (secondMediaPlayerInternal != null) {
                 secondMediaPlayerInternal.Dispose();
             }
             if (currentMediaInternal != null) {
                 currentMediaInternal.Dispose();
                 currentMediaInternal = null;
             }
             if (nextMediaInternal != null) {
                 nextMediaInternal.Dispose();
                 nextMediaInternal = null;
             }
         }
     } finally {
         base.Dispose(isDisposing);
     }
 }
예제 #9
0
 /// <summary>
 /// Stop the current media playing and begin playing next.
 /// </summary>
 public override void PlayNext() {
     VerifyObjectIsNotDisposed();
     //
     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);
         }
     }
     //
     if (nextMediaInternal == null) {
         // Create nextMediaInternal and start playing in the inactiveWindow
         nextMediaInternal = internalObjectsFactory.CreateVlcMediaInternal(nextMedia);
         nextMediaInternal.SetOutput(playerOutput);
         getNextMediaPlayerInternal().SetMedia(nextMediaInternal);
         getNextMediaPlayerInternal().SetDisplayOutput((int) ((DoubleWindowBase) playerOutput.Window).GetInactiveWindowHandleInternal());
         //
         startPlaying(getNextMediaPlayerInternal(), nextMediaInternal);
     } else {
         if (nextMediaInternal.State != VlcMediaState.PAUSED) {
             throw new MediaPlayerException("Next media has an unexpected state now.");
         }
         //
         getNextMediaPlayerInternal().Pause();
     }
     //
     waitForMediaState(nextMediaInternal, VlcMediaState.PLAYING);
     if (nextMediaInternal.State != VlcMediaState.PLAYING) {
         throw new VlcTimeoutException("Timeout waiting required state.");
     }
     //
     ((DoubleWindowBase) playerOutput.Window).SwitchWindowsInternal();
     // It is important to call this BEFORE stopping the player
     // if we want to EndReached event will not be raised incorrectly
     switchCurrentAndNextMediaPlayersInternal();
     //
     if (currentMediaInternal != null) {
         if ((currentMediaInternal.State != VlcMediaState.IDLE_CLOSE) &&
             (currentMediaInternal.State != VlcMediaState.ENDED)) {
             // It was _current_ player before the switchCurrentAndNextMediaPlayersInternal() call
             getNextMediaPlayerInternal().Stop();
             //
             waitForMediaState(currentMediaInternal, VlcMediaState.ENDED);
             if (currentMediaInternal.State != VlcMediaState.ENDED) {
                 throw new VlcTimeoutException("Timeout waiting required state.");
             }
         }
         //
         currentMediaInternal.Dispose();
         currentMediaInternal = null;
     }
     // current := next
     currentMediaInternal = nextMediaInternal;
     nextMediaInternal = null;
     currentMedia = nextMedia;
     nextMedia = null;
     //
     ((DoubleWindowBase) playerOutput.Window).PlayerVisibleInternal = true;
 }
예제 #10
0
        private void stop() {
            ((DoubleWindowBase) playerOutput.Window).PlayerVisibleInternal = false;
            //
            stopWaitingFiltersThread();

            if (currentMediaInternal != null) {
                if ((currentMediaInternal.State != VlcMediaState.ENDED) &&
                    (currentMediaInternal.State != VlcMediaState.IDLE_CLOSE)) {
                    //
                    getCurrentMediaPlayerInternal().Stop();
                    waitForMediaState(currentMediaInternal, VlcMediaState.ENDED);
                    //
                    if (currentMediaInternal.State != VlcMediaState.ENDED) {
                        throw new VlcTimeoutException("Timeout waiting required state.");
                    }
                }
                currentMediaInternal.Dispose();
                currentMediaInternal = null;
            }
            //
            if (nextMediaInternal != null) {
                if ((nextMediaInternal.State != VlcMediaState.ENDED) &&
                    (nextMediaInternal.State != VlcMediaState.IDLE_CLOSE)) {
                    //
                    getNextMediaPlayerInternal().Stop();
                    waitForMediaState(nextMediaInternal, VlcMediaState.ENDED);
                    //
                    if (nextMediaInternal.State != VlcMediaState.ENDED) {
                        throw new VlcTimeoutException("Timeout waiting required state.");
                    }
                }
                nextMediaInternal.Dispose();
                nextMediaInternal = null;
            }
        }
예제 #11
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>
 public override void Play() {
     VerifyObjectIsNotDisposed();
     //
     if (logger.IsTraceEnabled) {
         logger.Trace("Play method called.");
     }
     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);
         }
     }
     // Create the internal medias and start playing
     currentMediaInternal = internalObjectsFactory.CreateVlcMediaInternal(currentMedia);
     currentMediaInternal.SetOutput(playerOutput);
     getCurrentMediaPlayerInternal().SetMedia(currentMediaInternal);
     getCurrentMediaPlayerInternal().SetDisplayOutput((int) ((DoubleWindowBase) playerOutput.Window).GetActiveWindowHandleInternal());
     //
     getCurrentMediaPlayerInternal().Play();
     //
     startPlaying(getCurrentMediaPlayerInternal(), currentMediaInternal);
     // If nextMedia was specified, preparing it too
     if (nextMedia != null) {
         prepareNextMedia();
     }
     //
     ((DoubleWindowBase) playerOutput.Window).PlayerVisibleInternal = true;
 }