public void Init() { PresentParameters present_params = new PresentParameters(); present_params.Windowed = true; present_params.SwapEffect = SwapEffect.Discard; _device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, present_params); font = new Microsoft.DirectX.Direct3D.Font(_device, 20, 0, FontWeight.Bold, 0, false, CharacterSet.Default, Precision.Default, FontQuality.Default, PitchAndFamily.DefaultPitch, "Arial"); _video = new Video("clock.avi"); _video.TextureReadyToRender += new TextureRenderEventHandler(_video_TextureReadyToRender); _video.RenderToTexture(_device); vertices = new CustomVertex.PositionTextured[6]; vertices[0].Position = new Vector3(1f, 1f, 0f); vertices[0].Tu = 0; vertices[0].Tv = 1; vertices[1].Position = new Vector3(-1f, -1f, 0f); vertices[1].Tu = 1; vertices[1].Tv = 1; vertices[2].Position = new Vector3(1f, -1f, 0f); vertices[2].Tu = 0; vertices[2].Tv = 0; vertices[3].Position = new Vector3(-1.1f, -0.99f, 0f); vertices[3].Tu = 1; vertices[3].Tv = 0; vertices[4].Position = new Vector3(0.99f, 1.1f, 0f); vertices[4].Tu = 0; vertices[4].Tv = 0; vertices[5].Position = new Vector3(-1.1f, 1.1f, 0f); vertices[5].Tu = 1; vertices[5].Tv = 1; }
public void PlayMedia(Media media) { try { if (media is Audio) { //Playing the sound this.engine.Play2D(media.getUrl(), false); } else if (media is Video) { //Taking note of the video before it was replaced if (this.currentVideo != null && this.lastPlayedVideoUrl != media.getUrl()) { this.videoToDispose = this.currentVideo; } if (this.loadedVideo != null) { this.currentVideo = this.loadedVideo; } else { //Playing the video this.currentVideo = Microsoft.DirectX.AudioVideoPlayback.Video.FromFile(media.getUrl(), false); this.currentVideo.HideCursor(); } PlayFullScreenVideo(this.lastPlayedVideoUrl == media.getUrl()); this.lastPlayedVideoUrl = media.getUrl(); } } catch (Microsoft.DirectX.DirectXException) { //Video file not existing } }
public void LoadMediaListByIndex(int stepIndex) { if (this.lastLoadedIndex != stepIndex) { //Dispose of loadedVideo if not being played if (this.loadedVideo != null && this.loadedVideo != this.currentVideo) { this.DisposeVideo(ref this.loadedVideo); } this.loadedVideo = null; var actions = this.mediaList[stepIndex]; // Execute each action at this position for (var i = 0; i < actions.Length; i++) { Media selectedItem = actions[i]; //Load the media LoadMedia(selectedItem); } this.lastLoadedIndex = stepIndex; } }
private void lstVideos_SelectedIndexChanged(object sender, EventArgs e) { try { video.Stop(); video.Dispose(); } catch { } timerVideo.Enabled = false; int index = listaVideos.SelectedIndex; _selectedIndex = index; video = new Microsoft.DirectX.AudioVideoPlayback.Video(_videoPaths[index], false); video.Owner = painelVideo; painelVideo.Size = _pnlSize; do { var currentAnimal = _container.GetInstance <FormVideoAnalyzerSelecionaAnimal>(); currentAnimal.ShowDialog(); if (currentAnimal.AnimalSelecionado == null) { return; } IdAnimalEmAnalise = currentAnimal.AnimalSelecionado.IdAnimal; } while (IdAnimalEmAnalise == Guid.Empty); video.Play(); btnPlay.Image = Resources.Knob_Pause; video.Ending += Video_Ending; txtDiretorio.Text = listaVideos.Text; trackBarVideoProgress.Maximum = Convert.ToInt32(video.Duration); timerVideo.Enabled = true; }
private TimeSpan GetDuration() { // TODO: What should we do if DirectX throws an exception (e.g. the path is really // not a valid audio or video stream)? For now, just ignore exceptions. try { if (SessionComponentDefinition.GetIsAudio(Path)) { using (var audio = new Microsoft.DirectX.AudioVideoPlayback.Audio(Path)) { return(TimeSpan.FromSeconds((int)audio.Duration)); } } else if (SessionComponentDefinition.GetIsVideo(Path)) { using (var video = new Microsoft.DirectX.AudioVideoPlayback.Video(Path)) { return(TimeSpan.FromSeconds((int)video.Duration)); } } } catch (ThreadAbortException) { //fine, just return } catch (Exception e) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem(e, "Could not get duration of " + Path); } return(new TimeSpan()); }
/// <summary> /// Creates a new Video. /// </summary> /// <param name="filename">The filename for the Video.</param> public Video(string filename) { vid = new Microsoft.DirectX.AudioVideoPlayback.Video(filename, false); CurrentState = MediaStates.Stopped; vid.Ending += new System.EventHandler(OnEnding); vid.TextureReadyToRender += new Microsoft.DirectX.AudioVideoPlayback.TextureRenderEventHandler(OnTextureReady); }
public void Clear() { Stop(); playlist.Clear(); video?.Dispose(); video = null; trackBar.Value = 0; trackBar.Enabled = false; }
/// <summary> /// Dispose of the video if not null /// </summary> /// <param name="video"></param> public void DisposeVideo(ref Microsoft.DirectX.AudioVideoPlayback.Video video) { if (video != null && video.Disposed == false) { if (video.Playing == true) { video.Stop(); } video.Dispose(); video = null; } }
public void Open(Video source) { Clear(); Size size = outputFrame.Size; video = new Microsoft.DirectX.AudioVideoPlayback.Video(source.Path) { Owner = outputFrame }; outputFrame.Size = size; playlist.AddRange(source.Markers); trackBar.Maximum = (int)video.Duration; trackBar.Enabled = !cut.Checked; video.Audio.Volume = volumeBar.Value; }
public void LoadMedia(Media media) { try { if (media is Audio) { //Loads the sound this.engine.Play2D(media.getUrl(), false, true); } else if (media is Video) { //Loads the video this.loadedVideo = Microsoft.DirectX.AudioVideoPlayback.Video.FromFile(media.getUrl(), false); this.loadedVideo.HideCursor(); this.loadedVideo.Owner = this.loadForm.panVideo; this.loadedVideo.StopWhenReady(); } } catch (Microsoft.DirectX.DirectXException) { //Video file not existing } }
void CreateVideoObject() { if (video != null) { video.TextureReadyToRender -= new Microsoft.DirectX.AudioVideoPlayback.TextureRenderEventHandler(video_TextureReadyToRender); video.Ending -= new EventHandler(video_Ending); video.Dispose(); video = null; } video = new Microsoft.DirectX.AudioVideoPlayback.Video("mms://stream1.halsc.com/mitomitomi/test.wmv", true); //video = new Microsoft.DirectX.AudioVideoPlayback.Video("mms://10.0.1.173:8070", true); video.TextureReadyToRender += new Microsoft.DirectX.AudioVideoPlayback.TextureRenderEventHandler(video_TextureReadyToRender); video.Ending += new EventHandler(video_Ending); video.RenderToTexture(d3ddevice); }