home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / MMSTEREO / MLTVID.CPP < prev    next >
Text File  |  1995-05-01  |  7KB  |  174 lines

  1. #include "mltvid.hpp"
  2.  
  3. /*------------------------------------------------------------------------------
  4. | VIDEO::VIDEO                                                                   |
  5. |                                                                              |
  6. |                                                                              |
  7. ------------------------------------------------------------------------------*/
  8. VIDEO::VIDEO( IMMDigitalVideo*  aVideoPlayer,
  9.               unsigned long     windowid,
  10.               IWindow*          parent,
  11.               IWindow*          owner)
  12.      : IMMPlayerPanel(windowid,parent,owner,IMMDevice::digitalVideo),
  13.        readout       (VIDEOREADOUTID, this,this),
  14.        name          (VIDEONAMEID, this, this),
  15.        pVideoPlayer  (aVideoPlayer),
  16.        observer      (0),
  17.        handler       (0)
  18. {
  19.    setPlayableDevice(pVideoPlayer);
  20.  
  21.    loadit= new IAnimatedButton(VIDEOLOADID,this,this,IRectangle(),
  22.                     IWindow::visible | IAnimatedButton::animateWhenLatched);
  23.    //Add the additional buttons to the player panel.
  24.    addToCell(&readout ,     9, 1, 1, 2);
  25.    addToCell(loadit   ,    11, 1, 1, 2);
  26.    addToCell(&name    ,     2, 3, 5, 1);
  27.    playButton()->disable();
  28.    rewindButton()->disable();
  29.    fastForwardButton()->disable();
  30.    stepForwardButton()->disable();
  31.    stepBackwardButton()->disable();
  32.  
  33.    //Put the bitmaps on the button.
  34.    loadit->setBitmaps(IAnimatedButton::eject);
  35.  
  36.    //Put text on the button.
  37.    loadit->setText("Load");
  38.  
  39.    //Set up the title
  40.    name.setText("Class Library Video Player");
  41.    name.setForegroundColor(IColor(IColor::red));
  42.  
  43.    //Set up the display
  44.    IFont("LED",10).setWindowFont(&readout);
  45.    readout.setForegroundColor(IColor(0,160,0));
  46.    readout.setBackgroundColor(IColor(IColor::black));
  47.    readout.setText("HR:MIN:SEC 00:00:00");
  48.    readout.setLimit(22);
  49.  
  50.    if (pVideoPlayer)
  51.    {
  52.       handler  = new VideoHandler();
  53.       handler->handleEventsFor(this);
  54.       observer = new VideoObserver(*this);
  55.       observer->handleNotificationsFor(*pVideoPlayer);
  56.    }
  57. }
  58.  
  59.  
  60. /*------------------------------------------------------------------------------
  61. | VIDEO::~VIDEO                                                                      |
  62. |                                                                              |
  63. |                                                                              |
  64. ------------------------------------------------------------------------------*/
  65. VIDEO::~VIDEO()
  66. {
  67.   if (observer)
  68.      observer->stopHandlingNotificationsFor(*pVideoPlayer);
  69.   if (handler)
  70.      handler->stopHandlingEventsFor(this);
  71. }
  72.  
  73.  
  74. /*------------------------------------------------------------------------------
  75. | VIDEO::videoPlayer                                                             |
  76. |                                                                              |
  77. |                                                                              |
  78. ------------------------------------------------------------------------------*/
  79. IMMDigitalVideo* VIDEO::videoPlayer () const
  80. {
  81.   return pVideoPlayer;
  82. }
  83.  
  84.  
  85. /*------------------------------------------------------------------------------
  86. | VideoHandler::VideoHandler                                                     |
  87. |                                                                              |
  88. |                                                                              |
  89. ------------------------------------------------------------------------------*/
  90. VideoHandler::VideoHandler()
  91.           : VideoHandler::Inherited()
  92. {}
  93.  
  94. /*------------------------------------------------------------------------------
  95. | VideoHandler::command                                                         |
  96. |                                                                              |
  97. ------------------------------------------------------------------------------*/
  98. Boolean VideoHandler::command(ICommandEvent& event)
  99. {
  100.   Boolean handled = false;
  101.   VIDEO* panel = 0;
  102.  
  103.   switch (event.commandId())
  104.   {
  105.     case VIDEOLOADID:
  106.          {
  107.          panel = (VIDEO*) (event.window());
  108.          IFileDialog::Settings fdSettings;
  109.          fdSettings.setTitle("Load a new video file");
  110.          fdSettings.setFileName("*.avi");
  111.          IFileDialog fd(panel->desktopWindow(),panel,fdSettings);
  112.          if (fd.pressedOK())
  113.          {
  114.             panel->videoPlayer()->loadOnThread(fd.fileName());
  115.             stop(*panel);
  116.             panel->videoPlayer()->startPositionTracking(IMMTime(3000));
  117.             panel->playButton()->enable();
  118.             panel->rewindButton()->enable();
  119.             panel->fastForwardButton()->enable();
  120.             panel->stepForwardButton()->enable();
  121.             panel->stepBackwardButton()->enable();
  122.          }
  123.          }
  124.          handled=true;
  125.          break;
  126.     default:
  127.          handled = Inherited::command(event);
  128.          break;
  129.   } /* endswitch */
  130.   return handled;
  131. }
  132.  
  133.  
  134. /*------------------------------------------------------------------------------
  135. | VideoObserver::VideoObserver                                                   |
  136. |                                                                              |
  137. |                                                                              |
  138. ------------------------------------------------------------------------------*/
  139. VideoObserver::VideoObserver(VIDEO& videoPanel)
  140.           : VideoObserver::Inherited(),
  141.           panel(videoPanel)
  142. {}
  143.  
  144. /*------------------------------------------------------------------------------
  145. | VideoObserver::dispatchNotificationEvent                                      |
  146. |                                                                              |
  147. |                                                                              |
  148. ------------------------------------------------------------------------------*/
  149. VideoObserver& VideoObserver::dispatchNotificationEvent(const INotificationEvent& event)
  150. {
  151.    if (event.notificationId() == IMMDevice::positionChangeId)
  152.    {
  153.       IMMPositionChangeEvent* positionEvent = (IMMPositionChangeEvent*)(event.eventData().asUnsignedLong());
  154.  
  155.       IMMTime time(positionEvent->position());
  156.       panel.readout.setText(IString("HR:MIN:SEC ") +
  157.                       IString(time.hours()).rightJustify(2,'0') +
  158.                       ":" +
  159.                       IString(time.minutes()).rightJustify(2,'0') +
  160.                       ":" +
  161.                       IString(time.seconds()).rightJustify(2,'0'));
  162.       if (!panel.playButton()->isLatched())
  163.          if (panel.videoPlayer()->mode()==IMMDevice::playing)
  164.             panel.playButton()->latch();
  165.    } /* endif */
  166.    if (event.notificationId() == IMMDevice::commandNotifyId)
  167.    {
  168.       IMMNotifyEvent* notifyEvent = (IMMNotifyEvent*)(event.eventData().asUnsignedLong());
  169.       if (notifyEvent->command() == IMMNotifyEvent::play)
  170.          panel.playButton()->unlatch();
  171.    } /* endif */
  172.    return *this;
  173. }
  174.