diff --git a/bazaar/MediaPlayer/MediaPlayer.upp b/bazaar/MediaPlayer/MediaPlayer.upp deleted file mode 100644 index f940422ab..000000000 --- a/bazaar/MediaPlayer/MediaPlayer.upp +++ /dev/null @@ -1,15 +0,0 @@ -uses - CtrlLib, - Controls4U, - GridCtrl, - Media, - SliderCtrlX; - -file - main.cpp, - demo.lay, - srcdoc.tpp; - -mainconfig - "" = "GUI MT"; - diff --git a/bazaar/MediaPlayer/Media_demo.upp b/bazaar/MediaPlayer/Media_demo.upp new file mode 100644 index 000000000..35e38b5e1 --- /dev/null +++ b/bazaar/MediaPlayer/Media_demo.upp @@ -0,0 +1,19 @@ +description "Media package examples\377"; + +uses + CtrlLib, + Controls4U, + Media; + +file + main.cpp, + demo.lay, + demoMediaPlayer.cpp, + demoMediaPlayer.lay, + demoVolumeCtrl.cpp, + demoVolumeCtrl.lay, + srcdoc.tpp; + +mainconfig + "" = "GUI MT"; + diff --git a/bazaar/MediaPlayer/demo.lay b/bazaar/MediaPlayer/demo.lay index 45def35ea..b95194a32 100644 --- a/bazaar/MediaPlayer/demo.lay +++ b/bazaar/MediaPlayer/demo.lay @@ -1,32 +1,6 @@ -LAYOUT(Main, 320, 300) - ITEM(Label, secondsLabel, SetFrame(FieldFrame()).RightPosZ(148, 56).BottomPosZ(49, 19)) - ITEM(Button, butPause, SetLabel(t_("Pause")).RightPosZ(52, 40).BottomPosZ(48, 20)) - ITEM(Button, butFormat, SetLabel(t_("Format")).RightPosZ(8, 40).BottomPosZ(24, 20)) - ITEM(Button, butPlay, SetLabel(t_("Play")).RightPosZ(96, 48).BottomPosZ(48, 20)) - ITEM(EditFile, file, HSizePosZ(4, 208).BottomPosZ(49, 19)) - ITEM(Option, blackWhite, SetLabel(t_("Grayscale effect")).LeftPosZ(188, 100).BottomPosZ(5, 19)) - ITEM(Option, motionDetect, SetLabel(t_("Motion detect")).LeftPosZ(96, 88).BottomPosZ(5, 19)) - ITEM(Option, showLogo, SetLabel(t_("Show logo")).LeftPosZ(188, 72).BottomPosZ(25, 19)) - ITEM(Option, rgb, SetLabel(t_("RGB/YUV")).LeftPosZ(96, 68).BottomPosZ(25, 19)) - ITEM(Option, fullScreen, SetLabel(t_("Full screen")).LeftPosZ(4, 88).BottomPosZ(5, 19)) - ITEM(Option, forceAspect, SetLabel(t_("Force aspect")).LeftPosZ(4, 88).BottomPosZ(25, 19)) - ITEM(EditString, seconds, RightPosZ(148, 56).BottomPosZ(49, 19)) - ITEM(SliderCtrlX, slider, HSizePosZ(4, 8).BottomPosZ(64, 40)) - ITEM(Button, butStop, SetLabel(t_("Stop")).RightPosZ(8, 40).BottomPosZ(48, 20)) - ITEM(MediaPlayer, player, SetFrame(InsetFrame()).HSizePosZ(4, 4).VSizePosZ(4, 104)) -END_LAYOUT - -LAYOUT(Format, 400, 392) - ITEM(ArrayCtrl, arrAudio, HSizePosZ(4, 4).TopPosZ(200, 100)) - ITEM(Label, dv___1, SetLabel(t_("Audio streams")).LeftPosZ(4, 104).TopPosZ(180, 19)) - ITEM(ArrayCtrl, arrVideo, HSizePosZ(4, 4).TopPosZ(68, 100)) - ITEM(Label, dv___3, SetLabel(t_("Video streams")).LeftPosZ(4, 104).TopPosZ(48, 19)) - ITEM(Label, fileName, SetFrame(ThinInsetFrame()).HSizePosZ(64, 4).TopPosZ(4, 19)) - ITEM(Label, dv___5, SetLabel(t_("File name:")).LeftPosZ(4, 60).TopPosZ(4, 19)) - ITEM(Label, duration, SetFrame(ThinInsetFrame()).LeftPosZ(64, 60).TopPosZ(24, 19)) - ITEM(Label, dv___7, SetLabel(t_("Duration:")).LeftPosZ(4, 60).TopPosZ(24, 19)) - ITEM(Button, ok, SetLabel(t_("Close")).RightPosZ(4, 64).BottomPosZ(4, 20)) - ITEM(DocEdit, tags, SetFrame(ThinInsetFrame()).WantFocus(false).SetEditable(false).HSizePosZ(4, 84).VSizePosZ(324, 4)) - ITEM(Label, dv___10, SetLabel(t_("Tags")).LeftPosZ(4, 30).TopPosZ(304, 19)) +LAYOUT(Main, 400, 164) + ITEM(ArrayCtrl, grid, HSizePosZ(4, 4).VSizePosZ(32, 4)) + ITEM(Label, dv___1, SetLabel(t_("Choose a Media demo")).LeftPosZ(8, 128).TopPosZ(8, 19)) + ITEM(Button, butRun, SetLabel(t_("Run")).RightPosZ(4, 76).TopPosZ(4, 24)) END_LAYOUT diff --git a/bazaar/MediaPlayer/demoMediaPlayer.cpp b/bazaar/MediaPlayer/demoMediaPlayer.cpp new file mode 100644 index 000000000..5b918e9e6 --- /dev/null +++ b/bazaar/MediaPlayer/demoMediaPlayer.cpp @@ -0,0 +1,393 @@ +#include + +using namespace Upp; + +#include +#include +#include + +#define LAYOUTFILE +#include + +struct MediaPlayerDemo : public WithMainMediaPlayer { +typedef MediaPlayerDemo CLASSNAME; + void Play() { + butPlay.Disable(); + butPause.Enable(); + butStop.Enable(); + butFormat.Disable(); + file.Disable(); + seconds.Hide(); + secondsLabel.SetText("0"); + sliderPosition.SetData(0); + + if (!player.Play()) + Exclamation(player.GetError()); + + seconds.SetText("0"); + sliderPosition.SetData(0); + butPlay.Enable(); + butPause.Disable(); + butStop.Disable(); + butFormat.Enable(); + file.Enable(); + seconds.Show(); + } + void Stop() { + player.Stop(); + seconds.SetText("0"); + sliderPosition.SetData(0); + } + void Pause() { + player.Pause(); + } + void Load() { + if (!player.Load(~file)) { + Exclamation(player.GetError()); + return; + } + Layout(); + int duration = int(player.GetDuration()); + if (duration <= 0) + duration = 1; + sliderPosition.MinMax(0, duration); + if (duration < 20) { + sliderPosition.SetMajorTicks(5); + sliderPosition.SetMinorTicks(1); + } else if (duration < 60) { + sliderPosition.SetMajorTicks(10); + sliderPosition.SetMinorTicks(5); + } else if (duration < 60*10) { + sliderPosition.SetMajorTicks(60); + sliderPosition.SetMinorTicks(10); + } else if (duration < 60*60) { + sliderPosition.SetMajorTicks(10*60); + sliderPosition.SetMinorTicks(5*60); + } else { + sliderPosition.SetMajorTicks(15*60); + sliderPosition.SetMinorTicks(5*60); + } + sliderPosition.SetData(0); + sliderPosition.Enable(); + butFormat.Enable(); + butPlay.Enable(); + butStop.Enable(); + butPause.Enable(); + } + virtual void Close() { + player.Stop(); + TopWindow::Close(); + } + void BWEffect(SDLSurface &surface) { + static int x, y; + static bool left, up; + int width = int(surface.GetWidth()/3); + int height = int(surface.GetHeight()/3); + int delta = 2; + + if (!player.IsPaused()) { + if (left) + x -= delta; + else + x += delta; + if (up) + y -= delta; + else + y += delta; + if (x < 0) { + left = false; + x = 1; + } else if (x >= surface.GetWidth()-width) { + left = true; + x = surface.GetWidth()-width - 1; + } + if (y < 0) { + up = false; + y = 1; + } else if (y >= surface.GetHeight()-height) { + up = true; + y = surface.GetHeight()-height - 1; + } + } + for (int r = y; r < y+height; ++r) { + for (int c = x; c < x+width; ++c) { + byte bw = Grayscale(surface.GetPixel(c, r)); + surface.DrawPixel(c, r, Color(bw, bw, bw)); + } + } + surface.DrawRect(x, y, width, height, 1, Black()); + } + void MotionDetect(SDLSurface &surface) { + static Buffer img0; + static Buffer img1; + static bool which; + static int prevLen; + byte *prev, *actual; + const int delta = 3; + + int len = int(surface.GetWidth()*surface.GetHeight()/delta); + if (len != prevLen) { + img0.Alloc(len); + img1.Alloc(len); + } + if (which) { + prev = img0; + actual = img1; + which = false; + } else { + prev = img1; + actual = img0; + which = true; + } + + byte *preva, *actuala; + actuala = actual; + for (int r = 0; r < surface.GetHeight(); r+=delta) { + for (int c = 0; c < surface.GetWidth(); c+=delta) + *(actuala++) = Grayscale(surface.GetPixel(c, r)); + } + if (len != prevLen) { + prevLen = len; + return; + } + actuala = actual; + preva = prev; + for (int r = 0; r < surface.GetHeight(); r+=delta) { + for (int c = 0; c < surface.GetWidth(); c+=delta) { + if (abs(*(actuala++) - *(preva++)) > 10) + surface.FillRect(c, r, delta, delta, Blue()); + } + } + } + void OnFrame(SDLSurface &surface) { + surface.Lock(); + if (blackWhite) + BWEffect(surface); + if (showLogo) + surface.DrawImage(imLogo, 0, 0, Black()); + if (motionDetect) + MotionDetect(surface); + surface.Unlock(); + } + void OnSecond() { + double sec = player.GetSecond(); + secondsLabel.SetText(SecondsToString(int(sec), false)); + sliderPosition.SetData(int(sec)); + } + void OnPause() { + if (player.IsPaused()) { + seconds.Show(); + seconds = SecondsToString(player.GetSecond(), false); + } else + seconds.Hide(); + } + void OnSliderPosition() { + player.SetSecond(int(~sliderPosition)); + seconds = SecondsToString(player.GetSecond(), false); + } + void OnSliderVolume() { + player.SetAudioFactor(int(~sliderVolume)/100.); + } + void OnEditSeconds() { + player.SetSecond(StringToSeconds(seconds)); + } + void OnRgb() { + player.SetRGB(rgb); + motionDetect.Enable(rgb); + showLogo.Enable(rgb); + blackWhite.Enable(rgb); + } + void CheckOption(int ii, ArrayCtrl *arr) { + int num = 0; + for(int i = 0; i < arr->GetCount(); i++) { + if (arr->Get(i, 0)) + num++; + } + if (num > 1) { + Exclamation("It is possible to play only one stream"); + arr->Set(ii, 0, false); + } + } + /*void OnFullScreen() { + static Rect last; + Close(); + if (IsFullScreen()) { + FullScreen(false); + SetRect(last); + } else { + last = GetRect(); + FullScreen(true); + } + OpenMain(); + }*/ + void FormatDialog() { + WithFormat format; + + CtrlLayoutOK(format, "File format"); + format.duration.SetText(SecondsToString(player.GetDuration(), false)); + format.fileName.SetText(player.GetFileName()); + + format.arrVideo.SetLineCy(Draw::GetStdFontCy()+4); + format.arrVideo.AddColumn("Sel"); + format.arrVideo.AddColumn("Codec"); + format.arrVideo.AddColumn("Pixel Format"); + format.arrVideo.AddColumn("Lang"); + format.arrVideo.AddColumn("Width"); + format.arrVideo.AddColumn("Height"); + format.arrVideo.AddColumn("PAR width"); + format.arrVideo.AddColumn("PAR height"); + format.arrVideo.AddColumn("DAR width"); + format.arrVideo.AddColumn("DAR height"); + format.arrVideo.AddColumn("Frame rate fps"); + format.arrVideo.AddColumn("Tbr"); + format.arrVideo.AddColumn("Tbn"); + format.arrVideo.AddColumn("Tbc"); + format.arrVideo.AddColumn("Bitrate kbps"); + format.arrVideo.AddColumn("Tags"); + format.arrVideo.ColumnWidths("30 100 70 40 45 45 60 60 60 60 80 50 50 50 70 80"); + format.arrVideo.AutoHideSb().HeaderObject().Absolute(); + + Array