/// <summary> /// Disable audio during playback /// </summary> public void DisableAudio() { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_enableaudio(this.Handle, (int)SdlFlag.FalseValue); } }
/// <summary> /// Resize movie /// </summary> /// <param name="width">Scale movie height to this width in pixels</param> /// <param name="height">Scale movie height to this height in pixels</param> public void ScaleXY(int width, int height) { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_scaleXY(this.Handle, width, height); } }
/// <summary> /// Change size of movie by the same amount in both axes /// </summary> /// <param name="scalingFactor">scale both width and height by this factor</param> public void ScaleSize(int scalingFactor) { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_scale(this.Handle, scalingFactor); } }
/// <summary> /// Seeks a specified number of bytes forward in the movie stream. /// </summary> /// <param name="bytes">number of bytes to move forward in movie</param> public void Seek(int bytes) { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_seek(this.Handle, bytes); } }
/// <summary> /// Return size to normal /// </summary> public void ScaleNormal() { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_scale(this.Handle, 1); } }
/// <summary> /// Skip forward a certain number of seconds /// </summary> /// <param name="seconds">number of seconds to skip</param> public void Skip(float seconds) { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_skip(this.Handle, seconds); } }
/// <summary> /// Move the video display area within the destination surface /// </summary> /// <param name="axisX">move the display area to this</param> /// <param name="axisY">move the display area to this</param> public void Move(int axisX, int axisY) { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_move(this.Handle, axisX, axisY); } }
/// <summary> /// Sets the volume for the movie. /// </summary> /// <param name="volume">volume to set movie to.</param> public void AdjustVolume(int volume) { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_setvolume(this.Handle, volume); } }
/// <summary> /// Double size of movie /// </summary> public void ScaleDouble() { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_scale(this.Handle, 2); } }
/// <summary> /// Renders specified frame of movie. /// </summary> public void RenderFirstFrame() { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_renderFrame(this.Handle, 0); } }
/// <summary> /// This pauses playback of the movie /// </summary> public void Pause() { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_pause(this.Handle); } }
/// <summary> /// Sets the movie playback position to the start of the movie. /// </summary> public void Rewind() { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_rewind(this.Handle); } }
/// <summary> /// Renders specified frame of movie. /// </summary> /// <param name="frameNumber">frame number</param> public void RenderFrame(int frameNumber) { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_renderFrame(this.Handle, frameNumber); } }
/// <summary> /// Enable video during playback /// </summary> /// <remarks>Enabled by default</remarks> public void EnableVideo() { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_enablevideo(this.Handle, (int)SdlFlag.TrueValue); } }
/// <summary> /// Starts playback of a movie. /// </summary> /// <param name="repeat">Loop movie while playing</param> public void Play(bool repeat) { if (this.Handle != IntPtr.Zero) { this.Loop(repeat); Smpeg.SMPEG_play(this.Handle); } }
/// <summary> /// Starts playback of a movie. /// </summary> public void Play() { if (this.Handle != IntPtr.Zero) { this.Loop(false); Smpeg.SMPEG_play(this.Handle); } }
/// <summary> /// Move the video display area within the destination surface /// </summary> /// <param name="width">change width of display area</param> /// <param name="height">change height of display area</param> /// <param name="axisX">move the display area to this</param> /// <param name="axisY">move the display area to this</param> public void DisplayRegion( int width, int height, int axisX, int axisY) { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_setdisplayregion(this.Handle, axisX, axisY, width, height); } }
/// <summary> /// Stops playback of a movie. /// </summary> public void Stop() { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_stop(this.Handle); // It seems to take some time to actually stop. System.Threading.Thread.Sleep(5); } }
/// <summary> /// Create movie object from file /// </summary> /// <param name="file">filename of mpeg-1 movie.</param> public Movie(string file) { this.Handle = Smpeg.SMPEG_new(file, out this.movieInfo, (int)SdlFlag.TrueValue); if (this.Handle == IntPtr.Zero) { throw MovieStatusException.Generate(); } }
/// <summary> /// Renders final frame of movie and puts it on a surface /// </summary> /// <param name="surface">surface to display frame to</param> public void RenderFinalFrame(BaseSdlResource surface) { if (surface == null) { throw new ArgumentNullException("surface"); } if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_renderFinal(this.Handle, surface.Handle, 0, 0); } }
/// <summary> /// Display video surface /// </summary> /// <param name="resource">Surface to display movie object on</param> public void Display(BaseSdlResource resource) { if (resource == null) { throw new ArgumentNullException("resource"); } if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_setdisplay( this.Handle, resource.Handle, IntPtr.Zero, null); } }
/// <summary> /// Loop movie /// </summary> private void Loop(bool repeat) { if (this.Handle != IntPtr.Zero) { if (repeat) { Smpeg.SMPEG_loop(this.Handle, (int)SdlFlag.TrueValue); } else { Smpeg.SMPEG_loop(this.Handle, (int)SdlFlag.FalseValue); } } }
/// <summary> /// Closes Music handle /// </summary> protected override void CloseHandle() { try { if (this.Handle != IntPtr.Zero) { Smpeg.SMPEG_delete(this.Handle); this.Handle = IntPtr.Zero; } } catch (NullReferenceException) { } catch (AccessViolationException) { } finally { this.Handle = IntPtr.Zero; } }
/// <summary> /// /// </summary> public void Run() { Sdl.SDL_Event evt; bool quitFlag = false; int flags = (Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF | Sdl.SDL_ANYFORMAT); int bpp = 16; int width = 352; int height = 240; Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING); Sdl.SDL_WM_SetCaption("Tao.Sdl Example - SmpegPlayer", ""); surfacePtr = Sdl.SDL_SetVideoMode( width, height, bpp, flags); SdlMixer.Mix_OpenAudio(SdlMixer.MIX_DEFAULT_FREQUENCY, unchecked (Sdl.AUDIO_S16LSB), 2, 1024); Smpeg.SMPEG_Info info = new Smpeg.SMPEG_Info(); string filepath = @"../../"; if (File.Exists("Data/SdlExamples.SmpegPlayer.mpg")) { filepath = ""; } //SdlMixer.MixFunctionDelegate audioMixer = new SdlMixer.MixFunctionDelegate(this.player); //int freq; //short format; //int channels; SdlMixer.Mix_CloseAudio(); IntPtr intPtr = Smpeg.SMPEG_new(filepath + "Data/SdlExamples.SmpegPlayer.mpg", out info, 1); //Smpeg.SMPEG_enableaudio(intPtr, 0); //SdlMixer.Mix_QuerySpec(out freq, out unchecked(format), out channels); //Sdl.SDL_AudioSpec audiofmt = new Tao.Sdl.Sdl.SDL_AudioSpec(); //audiofmt.freq = freq; //audiofmt.format = unchecked(format); //audiofmt.channels = (byte) channels; //Console.WriteLine("Freq: " + audiofmt.freq); //Console.WriteLine("Format: " + audiofmt.format); //Console.WriteLine("Channels: " + audiofmt.channels); Smpeg.SMPEG_getinfo(intPtr, out info); Console.WriteLine("Time: " + info.total_time.ToString()); Console.WriteLine("Width: " + info.width.ToString()); Console.WriteLine("Height: " + info.height.ToString()); Console.WriteLine("Size: " + info.total_size.ToString()); Console.WriteLine("Smpeg_error: " + Smpeg.SMPEG_error(intPtr)); //Smpeg.SMPEG_actualSpec(intPtr, ref audiofmt); //SdlMixer.Mix_HookMusic(audioMixer, intPtr); Smpeg.SMPEG_setdisplay(intPtr, surfacePtr, IntPtr.Zero, null); Smpeg.SMPEG_play(intPtr); //Smpeg.SMPEG_loop(intPtr, 1); //Smpeg.SMPEG_enableaudio(intPtr, 1); while ((Smpeg.SMPEG_status(intPtr) == Smpeg.SMPEG_PLAYING) && (quitFlag == false)) { Sdl.SDL_PollEvent(out evt); if (evt.type == Sdl.SDL_QUIT) { quitFlag = true; } else if (evt.type == Sdl.SDL_KEYDOWN) { if ((evt.key.keysym.sym == (int)Sdl.SDLK_ESCAPE) || (evt.key.keysym.sym == (int)Sdl.SDLK_q)) { quitFlag = true; } } } Smpeg.SMPEG_stop(intPtr); Smpeg.SMPEG_delete(intPtr); }