home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / JDirect / mediaplayer / formMediaPlayer.java < prev    next >
Encoding:
Java Source  |  2000-05-04  |  38.5 KB  |  1,225 lines

  1. import com.ms.wfc.app.*;
  2. import com.ms.wfc.core.*;
  3. import com.ms.wfc.ui.*;
  4. import com.ms.wfc.html.*;
  5. import com.ms.wfc.io.*;
  6.  
  7. /**
  8.  * This class can take a variable number of parameters on the command
  9.  * line. Program execution begins with the main() method. The class
  10.  * constructor is not invoked unless an object of type 'formMediaPlayer' is
  11.  * created in the main() method.
  12.  */
  13. public class formMediaPlayer extends Form
  14. {
  15.     int            currentMediaIndex        = 5;    // Currently selected Media (or the filter from the Open FileDialog)
  16.     int            prevMediaIndex            = -1;   // Previously selected Media 
  17.     Form        formAVI;                        // To refer to form displaying AVI
  18.     Form        formHelp;                        // To refer to form displaying help file
  19.     int            currentTrack            = 1;    // Current track on cd audio
  20.     int            totalTracks;                    // Total tracks on CD audio
  21.     String        mediaFileName;                    // Name of Media file selected
  22.     boolean        firstTime                = true; // Flag used while getting total tracks on cd audio
  23.     boolean        helpDisplayed            = false;// Flag to indicate if help is diplayed 
  24.     
  25.     // Friendly names for wav, midi, cd audio, avi files. Correspond to possible filters in the 
  26.     // OpenFileDialog box
  27.     public static final int MEDIA_SOUND                = 1;  
  28.     public static final int MEDIA_MIDI_SEQUENCER    = 2;
  29.     public static final int MEDIA_CD_AUDIO            = 3;
  30.     public static final int MEDIA_VIDEO_FOR_WINDOWS = 4;
  31.     public static final int MEDIA_ALL                = 5;
  32.     
  33.     public static final int NUM_DRIVES                = 26;
  34.         
  35.     static MCI_OPEN_PARMS    mciOpenParms    = new MCI_OPEN_PARMS();    
  36.     static int                wDeviceID        = 0;                    // Device ID of the device being played
  37.     static boolean            MediaPlaying    = false;                // Flags to indicate whether Media is  
  38.     static boolean            MediaPaused        = false;                // playing/paused or not
  39.     
  40.     public formMediaPlayer()
  41.     {
  42.         // Required for Visual J++ Form Designer support
  43.         initForm();    
  44.  
  45.         // TODO: Add any constructor code after initForm call
  46.         
  47.         this.setStartPosition(0); // Manual
  48.                 
  49.         // Disable menu item Close and also the buttons. Enable only when media is selected.
  50.         menuClose.setEnabled(false);
  51.         btnPlay.setEnabled(false);
  52.         btnStop.setEnabled(false);
  53.         btnSkip.setEnabled(false);
  54.                 
  55.         // Set Media Player display to approx. centre of screen
  56.         Rectangle rect = Screen.getBounds(this);
  57.         int centreX = (rect.width - rect.x) / 2;
  58.         int fractionX = Math.round((float) (0.7 * (centreX - rect.x)));
  59.         int centreY = (rect.height - rect.y) / 2;
  60.         int fractionY = Math.round((float) (0.6 * (centreY - rect.y))); 
  61.         this.setLeft(rect.x + fractionX) ;
  62.         this.setTop(rect.y + fractionY);
  63.         
  64.         // Initialize OpenFileDialog attributes. Add filters (*.wav,*.avi,etc)
  65.         openFileDlgOpen.reset();
  66.         openFileDlgOpen.setInitialDir(System.getProperty("com.ms.windir") + "\\MEDIA\\");
  67.         openFileDlgOpen.setFilter("Sound (*.wav)|*.wav|MIDI Sequencer (*.rmi;*.mid)|*.rmi;*.mid|CD Audio (*.cda)|*.cda|Video for Windows (*.avi)|*.avi|All files (*.*)|*.*");
  68.         openFileDlgOpen.addOnFileOk(new CancelEventHandler(this.formMediaPlayer_fileOK));
  69.         
  70.         // Initialize new form for siplaying AVI. Place it below the MediaPlayer display
  71.         formAVI = new Form();
  72.         formAVI.setVisible(false);
  73.     }
  74.     
  75.         
  76.     /**
  77.      * formMediaPlayer overrides dispose so it can clean up the
  78.      * component list.
  79.      */
  80.     public void dispose()
  81.     {
  82.         super.dispose();
  83.         components.dispose();
  84.     }
  85.  
  86.     // Play button click event handler 
  87.     private void btnPlay_click(Object source, Event e)
  88.     {
  89.         int returnVal = 0;
  90.         
  91.         timerMediaPlayed.setEnabled(true);
  92.         
  93.         // Alternate display between "Play" and "Pause". Call appropriate routines.
  94.         if ("Play".equals(btnPlay.getText()))
  95.         {
  96.             if (MediaPaused == false){
  97.                 // Play Media
  98.                 returnVal = PlayMedia(currentMediaIndex,mediaFileName,currentTrack,formAVI,this.getLeft(),this.getTop()+this.getHeight());
  99.             }
  100.              else
  101.                 // Resume paused Media 
  102.                  ResumeMedia(currentMediaIndex); 
  103.              if (returnVal >= 0 )
  104.              {
  105.                 labelStatus.setText(File.getName(mediaFileName) + " (Playing)");
  106.                 btnPlay.setText("Pause");
  107.                 btnStop.setEnabled(true);
  108.                 
  109.                 // Enable skip button only when media selected is cd audio
  110.                 if (currentMediaIndex == MEDIA_CD_AUDIO) 
  111.                     btnSkip.setEnabled(true);
  112.                 else
  113.                     btnSkip.setEnabled(false);
  114.              }
  115.         }
  116.         else
  117.         {
  118.             // Set Media Player caption to the media file selected
  119.             labelStatus.setText(File.getName(mediaFileName) + " (Paused)");         
  120.             PauseMedia(currentMediaIndex);
  121.             btnPlay.setText("Play");
  122.             btnStop.setEnabled(false);
  123.             
  124.             // Enable skip button only when media is cd audio
  125.             if (currentMediaIndex == MEDIA_CD_AUDIO) 
  126.                  btnSkip.setEnabled(true);
  127.              else
  128.                  btnSkip.setEnabled(false);
  129.         }
  130.     }
  131.  
  132.     // Stop button click event handler
  133.     private void btnStop_click(Object source, Event e)
  134.     {
  135.         // Stop playing media. Restore buttons to initial state.
  136.         timerMediaPlayed.setEnabled(false);        
  137.         btnPlay.setText("Play");
  138.         btnStop.setEnabled(false);
  139.         labelStatus.setText(File.getName(mediaFileName) + " (Stopped)");        
  140.         StopMedia(currentMediaIndex);
  141.         
  142.     }
  143.  
  144.     // Skip button click event handler. Skip button used for CD Audio to skip tracks
  145.     private void buttonSkip_click(Object source, Event e)
  146.     {
  147.         int returnVal;
  148.         
  149.         
  150.         if (firstTime) 
  151.         {
  152.             // Get the current track
  153.             currentTrack = GetCurrentTrack();
  154.             firstTime = false;
  155.             // Get total tracks
  156.             totalTracks = GetTotalTracks();
  157.         }
  158.                 
  159.         // If current track equals total track , skip to track 1 else increment track
  160.         if (currentTrack == totalTracks)
  161.             currentTrack = 1;
  162.         else
  163.             currentTrack = currentTrack + 1;
  164.         
  165.         // Display current track 
  166.         labelTrackDisplay.setText(" " + currentTrack + " ");
  167.         mediaFileName = "Track " + currentTrack;
  168.         
  169.         // Display current track on MediaPlayer caption
  170.         labelStatus.setText(File.getName(mediaFileName) + " (Stopped)");
  171.         StopMedia(currentMediaIndex);
  172.         if ("Pause".equals(btnPlay.getText())) 
  173.         {
  174.             // Start Playing next track
  175.             returnVal = PlayMedia(currentMediaIndex,mediaFileName,currentTrack,null,0,0);
  176.             // Set MediaPlayer caption to indicate media has started playing
  177.             labelStatus.setText(File.getName(mediaFileName) + " (Playing)");
  178.         }
  179.         
  180.     }
  181.         
  182.     // Open menu click event handler
  183.     private void menuOpen_click(Object source, Event e)
  184.     {
  185.         // Set filter to current media (default = MEDIA_ALL)
  186.         openFileDlgOpen.setFilterIndex(currentMediaIndex);
  187.         openFileDlgOpen.showDialog();
  188.     }
  189.  
  190.     
  191.     private void menuClose_click(Object source, Event e)
  192.     {
  193.         // If Media Playing then stop it.
  194.         if (MediaPlaying) 
  195.         {
  196.             StopMedia(currentMediaIndex);    
  197.             btnPlay.setText("Play");
  198.             MediaPlaying = false;
  199.         }
  200.         labelStatus.setText(" ");
  201.         
  202.         // Disable everything
  203.         timerMediaPlayed.setEnabled(false);
  204.         
  205.         // Disable all buttons, close menu and formAVI.
  206.         menuClose.setEnabled(false);
  207.         btnPlay.setEnabled(false);
  208.         btnStop.setEnabled(false);
  209.         btnSkip.setEnabled(false);
  210.         
  211.         labelTrackDisplay.setText("");
  212.         formAVI.setVisible(false);
  213.         openFileDlgOpen.setFileName("");        
  214.         uncheckMedia(currentMediaIndex);
  215.             
  216.     }
  217.  
  218.     // Exit menu click event handler
  219.     private void menuExit_click(Object source, Event e)
  220.     {
  221.         ExitMedia(currentMediaIndex);
  222.         
  223.         // Exit application
  224.         Application.exit();
  225.     }
  226.     
  227.     // Sound menu click event handler
  228.     private void menuSound_click(Object source, Event e)
  229.     {
  230.         // Open dialog box with filter set to (*.wav)        
  231.         openFileDlgOpen.setFilterIndex(1);
  232.         openFileDlgOpen.showDialog();
  233.     }
  234.     
  235.     // MIDI menu click event handler
  236.     private void menuMIDI_click(Object source, Event e)
  237.     {
  238.         // Open dialog box with filter set to (*.rmi;*.mid)        
  239.         openFileDlgOpen.setFilterIndex(2);
  240.         openFileDlgOpen.showDialog();
  241.     }
  242.  
  243.     // CD Audio menu click event handler
  244.     private void menuCDAudio_click(Object source, Event e)
  245.     {
  246.         
  247.         
  248.         // Do not pop up an open file dialog in this case
  249.         menuCDAudio.setChecked(true);
  250.         menuClose.setEnabled(true);
  251.         btnPlay.setEnabled(true);
  252.         btnSkip.setEnabled(true);
  253.         formAVI.setVisible(false);
  254.         prevMediaIndex = currentMediaIndex;
  255.         currentMediaIndex = MEDIA_CD_AUDIO;
  256.         checkCurrentMedia();
  257.         if ((prevMediaIndex != -1) && (currentMediaIndex != prevMediaIndex)) uncheckMedia(prevMediaIndex);
  258.         
  259.         // Pop up an error
  260.         if ((wDeviceID = FindDevice()) < 0) {
  261.              MessageBox.show("Error: CD-ROM device is either not installed or is being used by another application.","Error Message",MessageBox.OKCANCEL);
  262.             Application.exit();
  263.         }
  264.         CloseDevice();
  265.         labelTrackDisplay.setText(" " + currentTrack + " ");
  266.         labelStatus.setText("Track " + currentTrack + " (Stopped)");
  267.         mediaFileName = "Track " + currentTrack;
  268.     }
  269.     
  270.     // Video for Windows menu click event handler
  271.     private void menuVideoForWindows_click(Object source, Event e)
  272.     {
  273.         // Open dialog box with filter set to (*.avi)
  274.         openFileDlgOpen.setFilterIndex(4);
  275.         openFileDlgOpen.showDialog();
  276.     }
  277.  
  278.     
  279.     // OpenFileDialog OK button click event handler
  280.     void formMediaPlayer_fileOK(Object sender, CancelEvent e)
  281.     {
  282.         String fn;
  283.         String ext;
  284.             
  285.         // Make sure to stop currently playing media before opening another one
  286.         if (MediaPlaying)
  287.         {
  288.             btnPlay.setText("Play");
  289.             btnStop.setEnabled(false);
  290.             btnSkip.setEnabled(false);
  291.             labelStatus.setText(File.getName(mediaFileName) + " (Stopped)");        
  292.             StopMedia(currentMediaIndex);
  293.         }    
  294.         
  295.         mediaFileName = openFileDlgOpen.getFileName();
  296.         openFileDlgOpen.setFileName("");
  297.         
  298.         
  299.         menuClose.setEnabled(true);
  300.         btnPlay.setEnabled(true);
  301.         
  302.         formAVI.setVisible(false);
  303.         
  304.         prevMediaIndex = currentMediaIndex;
  305.         
  306.         // Make current media as whatever has been selected
  307.         if (openFileDlgOpen.getFilterIndex() == MEDIA_ALL)
  308.         {
  309.             fn = mediaFileName;
  310.             ext = fn.substring(fn.length() - 3);
  311.             if  (ext.equals("wav") || ext.equals("WAV")) currentMediaIndex = MEDIA_SOUND;
  312.             else
  313.             if  (ext.equals("rmi") || ext.equals("RMI") || ext.equals("mid") || ext.equals("MID")) currentMediaIndex = MEDIA_MIDI_SEQUENCER;
  314.             else
  315.             if  (ext.equals("avi") || ext.equals("AVI")) currentMediaIndex = MEDIA_VIDEO_FOR_WINDOWS;
  316.             else 
  317.             if  (ext.equals("cda") || ext.equals("CDA")) currentMediaIndex = MEDIA_CD_AUDIO;
  318.         }
  319.         else
  320.         {
  321.             fn = mediaFileName;
  322.             ext = fn.substring(fn.length() - 3);
  323.             int tmpMediaIndex = -1;
  324.             if  (ext.equals("wav") || ext.equals("WAV")) tmpMediaIndex = MEDIA_SOUND;
  325.             else
  326.             if  (ext.equals("rmi") || ext.equals("RMI") || ext.equals("mid") || ext.equals("MID")) tmpMediaIndex = MEDIA_MIDI_SEQUENCER;
  327.             else
  328.             if  (ext.equals("avi") || ext.equals("AVI")) tmpMediaIndex = MEDIA_VIDEO_FOR_WINDOWS;
  329.             else 
  330.             if  (ext.equals("cda") || ext.equals("CDA")) tmpMediaIndex = MEDIA_CD_AUDIO;
  331.             currentMediaIndex = openFileDlgOpen.getFilterIndex();
  332.             if (tmpMediaIndex != currentMediaIndex)
  333.             {
  334.                 currentMediaIndex = tmpMediaIndex;
  335.             }
  336.         }
  337.         
  338.         // Enable skip button when media selected is cd audio
  339.         if (currentMediaIndex == MEDIA_CD_AUDIO) 
  340.         {
  341.             btnSkip.setEnabled(true);
  342.         }
  343.         else
  344.         {
  345.             btnSkip.setEnabled(false);
  346.             labelTrackDisplay.setText("");
  347.         }    
  348.         
  349.         // Check the currently selected media menu item
  350.         checkCurrentMedia();
  351.         if ((prevMediaIndex != -1) && (currentMediaIndex != prevMediaIndex)) uncheckMedia(prevMediaIndex);
  352.         
  353.         if (currentMediaIndex == MEDIA_CD_AUDIO)
  354.         {
  355.             if ((wDeviceID = FindDevice()) < 0) {
  356.                 MessageBox.show("Error: CD-ROM device is either not installed or is being used by another application.","Error Message",MessageBox.OKCANCEL);
  357.                 Application.exit();
  358.             }
  359.             CloseDevice(); 
  360.             
  361.             // update label
  362.             labelTrackDisplay.setText(" " + currentTrack + " ");    
  363.             mediaFileName = "Track " + currentTrack;
  364.         }
  365.         labelStatus.setText(File.getName(mediaFileName) + " (Stopped)"); 
  366.         
  367.     }
  368.     
  369.     
  370.     // To check currently selected media menu item    
  371.     private void checkCurrentMedia()
  372.     {
  373.         switch (currentMediaIndex)
  374.         {
  375.             case MEDIA_SOUND            :    menuSound.setChecked(true);
  376.                                             break;
  377.                                 
  378.             case MEDIA_MIDI_SEQUENCER    :    menuMIDI.setChecked(true);
  379.                                             break;
  380.                                 
  381.             case MEDIA_CD_AUDIO            :    menuCDAudio.setChecked(true);
  382.                                             break;    
  383.                                             
  384.             case MEDIA_VIDEO_FOR_WINDOWS:    menuVideoForWindows.setChecked(true);
  385.                                             break;
  386.                                             
  387.             default                        :    break;
  388.         }
  389.     }
  390.     
  391.     // To uncheck a media menu item
  392.     private void uncheckMedia(int mediaIndex)
  393.     {
  394.         switch (mediaIndex)
  395.         {
  396.             case MEDIA_SOUND            :    menuSound.setChecked(false);
  397.                                             break;
  398.                                 
  399.             case MEDIA_MIDI_SEQUENCER    :    menuMIDI.setChecked(false);
  400.                                             break;
  401.                                 
  402.             case MEDIA_CD_AUDIO            :    menuCDAudio.setChecked(false);
  403.                                             break;    
  404.                                             
  405.             case MEDIA_VIDEO_FOR_WINDOWS:    menuVideoForWindows.setChecked(false);
  406.                                             break;
  407.                                             
  408.             default                        :    break;
  409.         }
  410.     }
  411.  
  412.     
  413.     // Timer used to find out when the media finished playing
  414.     private void timerMediaPlayed_timer(Object source, Event e)
  415.     {
  416.         int mciError;
  417.         MCI_STATUS_PARMS mciStatusParms = new MCI_STATUS_PARMS();
  418.         int length, position;
  419.         
  420.         if (MediaPlaying) {
  421.             
  422.             if (currentMediaIndex == MEDIA_CD_AUDIO)
  423.             {
  424.                 int tmpTrack;
  425.                 
  426.                 // Get the current track on cd audio
  427.                 tmpTrack = GetCurrentTrack();
  428.                 
  429.                 if (tmpTrack != currentTrack) {
  430.                     mediaFileName = "Track " + tmpTrack;
  431.                     
  432.                     // The last track on CD is being played, so stop when over
  433.                     if (currentTrack == totalTracks)
  434.                     {
  435.                         timerMediaPlayed.setEnabled(false);
  436.                         currentTrack = 1;    
  437.                         btnPlay.setText("Play");
  438.                         btnStop.setEnabled(false);
  439.                         labelStatus.setText(File.getName(mediaFileName) + " (Stopped)");
  440.                         labelTrackDisplay.setText(" " + currentTrack + " ");
  441.                         StopMedia(currentMediaIndex);
  442.                     }
  443.                     else
  444.                     {
  445.                         currentTrack = tmpTrack;
  446.                         labelStatus.setText(File.getName(mediaFileName) + " (Playing)");
  447.                         labelTrackDisplay.setText(" " + tmpTrack + " ");
  448.                     }
  449.                 }
  450.             }
  451.             else
  452.             {
  453.             
  454.             // Find out length of media being played
  455.             mciStatusParms.dwItem = MCI_STATUS_LENGTH;
  456.             mciError = mciSendCommand(wDeviceID, MCI_STATUS,MCI_STATUS_ITEM, mciStatusParms);
  457.             if (mciError != 0) {
  458.                 printMCIError(mciError);
  459.                 CloseDevice();
  460.             }
  461.             length = mciStatusParms.dwReturn;
  462.             
  463.             // Find out current position of the media being played
  464.             mciStatusParms.dwItem = MCI_STATUS_POSITION;
  465.             mciError = mciSendCommand(wDeviceID, MCI_STATUS,MCI_STATUS_ITEM, mciStatusParms);
  466.             if (mciError != 0) {
  467.                 printMCIError(mciError);
  468.                 CloseDevice();
  469.             }
  470.             position = mciStatusParms.dwReturn;
  471.             
  472.             // Media has finished playing
  473.             if (position == length)
  474.             {
  475.                 timerMediaPlayed.setEnabled(false);
  476.                 btnPlay.setText("Play");
  477.                 btnStop.setEnabled(false);
  478.                 btnSkip.setEnabled(false);
  479.                 labelStatus.setText(File.getName(mediaFileName) + " (Stopped)");        
  480.                 StopMedia(currentMediaIndex);
  481.             }
  482.             }
  483.             }
  484.     }
  485.     
  486.     void aboutForm_close(Object sender,CancelEvent e)
  487.     {
  488.         // Enable other forms on closing formAbout
  489.         this.setEnabled(true);    
  490.         formAVI.setEnabled(true);
  491.     }
  492.  
  493.     // The About Media Player click event handler
  494.     private void menuAbout_click(Object source, Event e)
  495.     {
  496.         Form formAbout;
  497.         Label labelAbout;
  498.         
  499.         // Create a form with a label within the form
  500.         // Display information in the label
  501.         
  502.         formAbout = new Form();
  503.         formAbout.addOnClosing(new CancelEventHandler(this.aboutForm_close));
  504.         formAbout.setText("About Media Player");
  505.         formAbout.setStartPosition(0);        // Manual
  506.         formAbout.setLocation(this.getLeft()+5,this.getTop()+5);
  507.         formAbout.setSize(this.getWidth()-10,this.getHeight()-20);
  508.         formAbout.setMaximizeBox(false);
  509.         formAbout.setMinimizeBox(false);
  510.         formAbout.setBorderStyle(this.getBorderStyle());
  511.         labelAbout = new Label();
  512.         labelAbout.setAutoSize(false);
  513.         labelAbout.setBorderStyle(2);
  514.         labelAbout.setLocation(labelAbout.getLeft()+5,labelAbout.getTop()+5);
  515.         Rectangle r = formAbout.getBounds();
  516.         labelAbout.setSize(r.width-20,r.height-40);
  517.         labelAbout.setBackColor(Color.LIGHTGRAY);
  518.         labelAbout.setForeColor(Color.BLACK);
  519.         labelAbout.setTextAlign(2);
  520.         labelAbout.setText("\r\nMicrosoft (R) Media Player\r\n");
  521.         labelAbout.setText(labelAbout.getText() + "Version 1.0\r\n");
  522.         labelAbout.setText(labelAbout.getText() + "Copyright (C) Microsoft Corp.");
  523.         
  524.         formAbout.add(labelAbout);
  525.         labelAbout.setVisible(true);
  526.         formAbout.setVisible(true);
  527.         
  528.         // Disable other forms until formAbout is closed 
  529.         this.setEnabled(false);
  530.         formAVI.setEnabled(false);
  531.     }
  532.  
  533.     
  534.     void helpForm_close(Object sender,CancelEvent e)
  535.     {
  536.         helpDisplayed = false;
  537.     }
  538.     
  539.     
  540.     // Help information
  541.     private void menuHelpTopics_click(Object source, Event e)
  542.     {
  543.         Label labelHelp;
  544.         
  545.         // Create a form with a label within the form
  546.         // Display information in the label
  547.         if (helpDisplayed == false) {
  548.             formHelp = new Form();
  549.             formHelp.addOnClosing(new CancelEventHandler(this.helpForm_close));
  550.             formHelp.setText("Help");
  551.             formHelp.setStartPosition(0);        // Manual
  552.             formHelp.setLocation(this.getLeft()-50,this.getTop());
  553.             formHelp.setSize(this.getWidth()+200,this.getHeight()+250);
  554.             formHelp.setMaximizeBox(false);
  555.             formHelp.setMinimizeBox(false);
  556.             formHelp.setBorderStyle(this.getBorderStyle());
  557.             labelHelp = new Label();
  558.             labelHelp.setAutoSize(false);
  559.             labelHelp.setBorderStyle(2);
  560.             labelHelp.setLocation(labelHelp.getLeft()+5,labelHelp.getTop()+5);
  561.             Rectangle r = formHelp.getBounds();
  562.             labelHelp.setSize(r.width-20,r.height-40);
  563.             labelHelp.setBackColor(Color.LIGHTGRAY);
  564.             labelHelp.setForeColor(Color.BLACK);
  565.             labelHelp.setTextAlign(0);
  566.             labelHelp.setText("MediaPlayer\r\n\r\nThe MediaPlayer is a classic example provided to play different kinds of media viz. Waveform (.WAV) files, MIDI files (.MID,.RMI), CD Audio (.CDA) and Video for Windows (.AVI) files.");
  567.             labelHelp.setText(labelHelp.getText() + "\r\n\r\nTo play .wav,.mid,.rmi,.avi files : \r\n --  Click on Device \r\n --  Click on the required media type \r\n --  Select a file from the Dialog Box and click OK \r\n --  Click on Play button \r\n --  To pause, click on Pause button \r\n --  To stop, click on Stop button");
  568.             labelHelp.setText(labelHelp.getText() + "\r\n\r\nTo play a track from CD : \r\n --  Click on Device \r\n --  Click on CD Audio \r\n --  Click on Play button. The media starts playing from track 1 \r\n --  To pause, click on Pause button \r\n --  To stop, click on Stop button \r\n --  To skip a track, click on Skip button. Pressing the skip button while last track is playing results in a skip to track 1.\r\n");
  569.             labelHelp.setText(labelHelp.getText() + "\r\n\r\n Alternately, the media can also be opened using the Open menu item of the File menu."); 
  570.             formHelp.add(labelHelp);
  571.             labelHelp.setVisible(true);
  572.             formHelp.setVisible(true);
  573.             helpDisplayed = true;
  574.         }
  575.         else
  576.         {
  577.             // Do not launch another help if help already present
  578.             // Just change focus to the original help window
  579.             formHelp.select();
  580.         }
  581.     }
  582.  
  583.     
  584.     /**
  585.      * NOTE: The following code is required by the Visual J++ form
  586.      * designer.  It can be modified using the form editor.  Do not
  587.      * modify it using the code editor.
  588.      */
  589.     Container components = new Container();
  590.     MainMenu mainMenuMediaPlayer = new MainMenu();
  591.     MenuItem menuHelp = new MenuItem();
  592.     MenuItem menuDevice = new MenuItem();
  593.     MenuItem menuFile = new MenuItem();
  594.     MenuItem menuAbout = new MenuItem();
  595.     MenuItem menuSeparatorHelpAbout = new MenuItem();
  596.     MenuItem menuHelpTopics = new MenuItem();
  597.     MenuItem menuCDAudio = new MenuItem();
  598.     MenuItem menuMIDI = new MenuItem();
  599.     MenuItem menuSound = new MenuItem();
  600.     MenuItem menuVideoForWindows = new MenuItem();
  601.     MenuItem menuExit = new MenuItem();
  602.     MenuItem menuSeparatorCloseExit = new MenuItem();
  603.     MenuItem menuClose = new MenuItem();
  604.     MenuItem menuOpen = new MenuItem();
  605.     Button btnPlay = new Button();
  606.     Button btnStop = new Button();
  607.     OpenFileDialog openFileDlgOpen = new OpenFileDialog();
  608.     Button btnSkip = new Button();
  609.     Label labelTrack = new Label();
  610.     Label labelTrackDisplay = new Label();
  611.     Label labelDisplay = new Label();
  612.     Timer timerMediaPlayed = new Timer(components);
  613.     Label labelStatus = new Label();
  614.  
  615.     private void initForm()
  616.     {
  617.         menuAbout.setText("&About Media Player");
  618.         menuAbout.addOnClick(new EventHandler(this.menuAbout_click));
  619.  
  620.         menuSeparatorHelpAbout.setText("-");
  621.  
  622.         menuHelpTopics.setText("&Help Topics");
  623.         menuHelpTopics.addOnClick(new EventHandler(this.menuHelpTopics_click));
  624.  
  625.         menuHelp.setMenuItems(new MenuItem[] {
  626.                               menuHelpTopics, 
  627.                               menuSeparatorHelpAbout, 
  628.                               menuAbout});
  629.         menuHelp.setText("&Help");
  630.  
  631.         menuCDAudio.setText("&3 CD Audio");
  632.         menuCDAudio.addOnClick(new EventHandler(this.menuCDAudio_click));
  633.  
  634.         menuMIDI.setText("&2 MIDI Sequencer...");
  635.         menuMIDI.addOnClick(new EventHandler(this.menuMIDI_click));
  636.  
  637.         menuSound.setText("&1 Sound...");
  638.         menuSound.addOnClick(new EventHandler(this.menuSound_click));
  639.  
  640.         menuVideoForWindows.setText("&4 Video for Windows...");
  641.         menuVideoForWindows.addOnClick(new EventHandler(this.menuVideoForWindows_click));
  642.  
  643.         menuDevice.setMenuItems(new MenuItem[] {
  644.                                 menuSound, 
  645.                                 menuMIDI, 
  646.                                 menuCDAudio, 
  647.                                 menuVideoForWindows});
  648.         menuDevice.setText("&Device");
  649.  
  650.         menuExit.setText("E&xit");
  651.         menuExit.addOnClick(new EventHandler(this.menuExit_click));
  652.  
  653.         menuSeparatorCloseExit.setText("-");
  654.  
  655.         menuClose.setText("&Close");
  656.         menuClose.addOnClick(new EventHandler(this.menuClose_click));
  657.  
  658.         menuOpen.setText("&Open");
  659.         menuOpen.addOnClick(new EventHandler(this.menuOpen_click));
  660.  
  661.         menuFile.setMenuItems(new MenuItem[] {
  662.                               menuOpen, 
  663.                               menuClose, 
  664.                               menuSeparatorCloseExit, 
  665.                               menuExit});
  666.         menuFile.setText("&File");
  667.  
  668.         mainMenuMediaPlayer.setMenuItems(new MenuItem[] {
  669.                                          menuFile, 
  670.                                          menuDevice, 
  671.                                          menuHelp});
  672.         /* @designTimeOnly mainMenuMediaPlayer.setLocation(new Point(120, -16)); */
  673.  
  674.         this.setBackColor(Color.LIGHTGRAY);
  675.         this.setFont(new Font("MS Sans Serif", 8.0f, FontSize.POINTS, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
  676.         this.setForeColor(Color.BLACK);
  677.         this.setText("Media Player");
  678.         this.setAutoScale(false);
  679.         this.setAutoScaleBaseSize(13);
  680.         this.setBorderStyle(FormBorderStyle.FIXED_SINGLE);
  681.         this.setClientSize(new Point(258, 124));
  682.         this.setMaximizeBox(false);
  683.         this.setMenu(mainMenuMediaPlayer);
  684.         this.setStartPosition(FormStartPosition.MANUAL);
  685.  
  686.         btnPlay.setEnabled(false);
  687.         btnPlay.setLocation(new Point(8, 56));
  688.         btnPlay.setSize(new Point(48, 24));
  689.         btnPlay.setTabIndex(0);
  690.         btnPlay.setText("Play");
  691.         btnPlay.addOnClick(new EventHandler(this.btnPlay_click));
  692.  
  693.         btnStop.setEnabled(false);
  694.         btnStop.setLocation(new Point(56, 56));
  695.         btnStop.setSize(new Point(48, 24));
  696.         btnStop.setTabIndex(1);
  697.         btnStop.setText("Stop");
  698.         btnStop.addOnClick(new EventHandler(this.btnStop_click));
  699.  
  700.         openFileDlgOpen.setInitialDir("c:\\");
  701.         openFileDlgOpen.setTitle("Open");
  702.         /* @designTimeOnly openFileDlgOpen.setLocation(new Point(264, -8)); */
  703.  
  704.         btnSkip.setEnabled(false);
  705.         btnSkip.setLocation(new Point(152, 56));
  706.         btnSkip.setSize(new Point(48, 24));
  707.         btnSkip.setTabIndex(2);
  708.         btnSkip.setText("Skip");
  709.         btnSkip.addOnClick(new EventHandler(this.buttonSkip_click));
  710.  
  711.         labelTrack.setFont(new Font("MS Sans Serif", 8.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  712.         labelTrack.setForeColor(Color.DARKGRAY);
  713.         labelTrack.setLocation(new Point(208, 40));
  714.         labelTrack.setSize(new Point(48, 13));
  715.         labelTrack.setTabIndex(3);
  716.         labelTrack.setTabStop(false);
  717.         labelTrack.setText("Track");
  718.         labelTrack.setAutoSize(true);
  719.  
  720.         labelTrackDisplay.setBackColor(Color.BLACK);
  721.         labelTrackDisplay.setFont(new Font("MS Sans Serif", 12.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  722.         labelTrackDisplay.setForeColor(Color.WHITE);
  723.         labelTrackDisplay.setLocation(new Point(200, 56));
  724.         labelTrackDisplay.setSize(new Point(48, 24));
  725.         labelTrackDisplay.setTabIndex(9);
  726.         labelTrackDisplay.setTabStop(false);
  727.         labelTrackDisplay.setText("");
  728.         labelTrackDisplay.setTextAlign(HorizontalAlignment.CENTER);
  729.  
  730.         labelDisplay.setBackColor(Color.LIGHTGRAY);
  731.         labelDisplay.setFont(new Font("Verdana", 18.0f, FontSize.POINTS, FontWeight.NORMAL, true, false, false, CharacterSet.DEFAULT, 0));
  732.         labelDisplay.setForeColor(new Color(128, 0, 0));
  733.         labelDisplay.setLocation(new Point(16, 8));
  734.         labelDisplay.setSize(new Point(216, 29));
  735.         labelDisplay.setTabIndex(8);
  736.         labelDisplay.setTabStop(false);
  737.         labelDisplay.setText("Media Player");
  738.         labelDisplay.setAutoSize(true);
  739.         labelDisplay.setTextAlign(HorizontalAlignment.CENTER);
  740.  
  741.         timerMediaPlayed.setInterval(400);
  742.         timerMediaPlayed.addOnTimer(new EventHandler(this.timerMediaPlayed_timer));
  743.         /* @designTimeOnly timerMediaPlayed.setLocation(new Point(176, -16)); */
  744.  
  745.         labelStatus.setBackColor(Color.LIGHTGRAY);
  746.         labelStatus.setFont(new Font("MS Sans Serif", 8.0f, FontSize.POINTS, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
  747.         labelStatus.setForeColor(Color.DARKGRAY);
  748.         labelStatus.setLocation(new Point(8, 104));
  749.         labelStatus.setSize(new Point(240, 16));
  750.         labelStatus.setTabIndex(7);
  751.         labelStatus.setTabStop(false);
  752.         labelStatus.setText("");
  753.         labelStatus.setBorderStyle(BorderStyle.FIXED_3D);
  754.  
  755.         this.setNewControls(new Control[] {
  756.                             labelStatus, 
  757.                             labelDisplay, 
  758.                             labelTrackDisplay, 
  759.                             labelTrack, 
  760.                             btnSkip, 
  761.                             btnStop, 
  762.                             btnPlay});
  763.     }
  764.  
  765.     /**
  766.      * The main entry point for the application. 
  767.      *
  768.      * @param args Array of parameters passed to the application
  769.      * via the command line.
  770.      */
  771.     public static void main(String args[])
  772.     {
  773.         Application.run(new formMediaPlayer());
  774.     }
  775.     
  776.     // Find CD audio device
  777.     public static int FindDevice() {
  778.         int iDrive, mciError;
  779.  
  780.         mciOpenParms.lpstrDeviceType = "cdaudio";
  781.         mciOpenParms.lpstrAlias = "myalias";
  782.         for (iDrive=0; iDrive < NUM_DRIVES; ++iDrive) {
  783.             Character tChar = new Character((char)('A' + iDrive));
  784.             mciOpenParms.wDeviceID = 0;
  785.             mciOpenParms.lpstrElementName = tChar.toString() + ":";
  786.  
  787.             mciError = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT|MCI_OPEN_ALIAS, mciOpenParms);
  788.             if (mciError == 0) {
  789.                 return(mciOpenParms.wDeviceID);
  790.             }
  791.         }
  792.         return (-1);
  793.     }
  794.  
  795.     // Used for printing errors generated by mci commands
  796.     public static void printMCIError(int mciError) {
  797.         StringBuffer sbuf = new StringBuffer(512);
  798.         boolean flag;
  799.         
  800.  
  801.         flag = mciGetErrorString(mciError, sbuf, sbuf.capacity()+1);
  802.         if (flag) 
  803.              MessageBox.show(sbuf.toString(),"Error Message",MessageBox.OKCANCEL);
  804.         else 
  805.              MessageBox.show("Call to mciGetErrorString() failed","Error Message",MessageBox.OKCANCEL);
  806.     }
  807.  
  808.     public static boolean SetTimeFormat() {
  809.         int mciError;
  810.         MCI_SET_PARMS mciSetParms = new MCI_SET_PARMS();
  811.         
  812.         mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF;
  813.         
  814.         mciError = mciSendCommand(wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, mciSetParms);
  815.  
  816.         if (mciError != 0) {
  817.             printMCIError(mciError);
  818.             return(false);
  819.         }
  820.         return(true);
  821.     }
  822.  
  823.     public static void ExitMedia(int mediaType) {
  824.         if (MediaPlaying) {
  825.             StopMedia(mediaType);
  826.         }
  827.     }
  828.  
  829.     public static void CloseDevice() {
  830.         int mciError;
  831.                 
  832.         mciError = mciSendCommand(wDeviceID, MCI_CLOSE, 0, 0);
  833.  
  834.         if (mciError != 0) {
  835.             printMCIError(mciError);
  836.         }
  837.     }
  838.  
  839.     public static void OpenDevice(int mediaType) {
  840.         int mciError;
  841.         int mciFlags;
  842.         
  843.         if (mediaType == MEDIA_CD_AUDIO)
  844.             mciFlags = MCI_OPEN_TYPE|MCI_OPEN_SHAREABLE|MCI_OPEN_ELEMENT|MCI_OPEN_ALIAS;
  845.         else
  846.             mciFlags = MCI_OPEN_TYPE|MCI_OPEN_ELEMENT;
  847.         mciError = mciSendCommand(0, MCI_OPEN, mciFlags, mciOpenParms);
  848.         if (mediaType == MEDIA_CD_AUDIO) SetTimeFormat();
  849.  
  850.         if (mciError != 0) {
  851.             printMCIError(mciError);
  852.         }
  853.     }
  854.  
  855.     // Gets total number of tracks on CD Audio
  856.     public static int GetTotalTracks() {
  857.         int mciError, dwFlags;
  858.         MCI_STATUS_PARMS mciStatusParms = new MCI_STATUS_PARMS();
  859.  
  860.         OpenDevice(MEDIA_CD_AUDIO);
  861.         dwFlags = MCI_STATUS_ITEM;
  862.         mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
  863.  
  864.         mciError = mciSendCommand(wDeviceID, MCI_STATUS, dwFlags, mciStatusParms);
  865.  
  866.         if (mciError != 0) {
  867.             printMCIError(mciError);
  868.             CloseDevice();
  869.             return(0);
  870.         }
  871.  
  872.         CloseDevice();
  873.         return(mciStatusParms.dwReturn);
  874.     }
  875.  
  876.     // Gets the current track being played on CD Audio
  877.     public static int GetCurrentTrack() {
  878.         int mciError, dwFlags;
  879.         MCI_STATUS_PARMS mciStatusParms = new MCI_STATUS_PARMS();
  880.  
  881.         OpenDevice(MEDIA_CD_AUDIO);
  882.         dwFlags = MCI_STATUS_ITEM;
  883.         mciStatusParms.dwItem = MCI_STATUS_CURRENT_TRACK;
  884.  
  885.         mciError = mciSendCommand(wDeviceID, MCI_STATUS, dwFlags, mciStatusParms);
  886.  
  887.         if (mciError != 0) {
  888.             printMCIError(mciError);
  889.             CloseDevice();
  890.             return(0);
  891.         }
  892.  
  893.         CloseDevice();
  894.         return(mciStatusParms.dwReturn);
  895.     }
  896.  
  897.     
  898.     public static int PlayMedia(int mediaType, String fileName,int track,Form f, int x, int y)
  899.     {
  900.         int mciError;
  901.         MCI_PLAY_PARMS mciPlayParms = new MCI_PLAY_PARMS();
  902.         MCI_STATUS_PARMS mciStatusParms = new MCI_STATUS_PARMS();
  903.         MCI_OVLY_WINDOW_PARMS mciWindowParms = new MCI_OVLY_WINDOW_PARMS();
  904.         MCI_OVLY_RECT_PARMS mciRectParms = new MCI_OVLY_RECT_PARMS();
  905.         
  906.         switch (mediaType)
  907.         {
  908.         
  909.             case MEDIA_SOUND            :    mciOpenParms.lpstrDeviceType = "waveaudio";
  910.                                             mciOpenParms.lpstrElementName = fileName;
  911.                                             OpenDevice(MEDIA_SOUND);
  912.                                             wDeviceID = mciOpenParms.wDeviceID;
  913.                                             
  914.                                             // Start playing
  915.                                             mciError = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY,mciPlayParms);
  916.                                             if (mciError != 0) {
  917.                                                 printMCIError(mciError);
  918.                                                 CloseDevice();
  919.                                                 return -1;
  920.                                             }
  921.                                             
  922.                                             MediaPlaying = true;
  923.                                             break;
  924.                                 
  925.             case MEDIA_MIDI_SEQUENCER    :    
  926.                                             mciOpenParms.lpstrDeviceType = "sequencer";
  927.                                             mciOpenParms.lpstrElementName = fileName;
  928.                                             mciOpenParms.lpstrAlias = "myalias1";
  929.                                             OpenDevice(MEDIA_MIDI_SEQUENCER);        
  930.                                             // The device opened successfully; get the device ID.
  931.                                             wDeviceID = mciOpenParms.wDeviceID;
  932.                                             
  933.                                             // Check if output port is MIDI mapper
  934.                                             mciStatusParms.dwItem = MCI_SEQ_STATUS_PORT;
  935.                                             mciError = mciSendCommand(wDeviceID, MCI_STATUS,MCI_STATUS_ITEM, mciStatusParms);
  936.                                             if (mciError != 0) {
  937.                                                 printMCIError(mciError);
  938.                                                 CloseDevice();
  939.                                                 return -1;
  940.                                             }    
  941.                                             
  942.                                             // Start playing
  943.                                             mciError = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY,mciPlayParms);
  944.                                             if (mciError != 0) {
  945.                                                 printMCIError(mciError);
  946.                                                 CloseDevice();
  947.                                                 return -1;
  948.                                             }
  949.                                             MediaPlaying = true;
  950.                                             
  951.                                             break;
  952.                                 
  953.             case MEDIA_CD_AUDIO            :    OpenDevice(MEDIA_CD_AUDIO);
  954.                                             mciPlayParms.dwFrom = track;
  955.                                             
  956.                                             // Start playing
  957.                                             mciError = mciSendCommand(wDeviceID, MCI_PLAY, MCI_FROM, mciPlayParms);
  958.                                             if (mciError != 0) {
  959.                                                  printMCIError(mciError);
  960.                                                  CloseDevice();
  961.                                                  return -1;
  962.                                             }
  963.                                             MediaPlaying = true;
  964.                                             CloseDevice();
  965.                                             break;    
  966.                                             
  967.             case MEDIA_VIDEO_FOR_WINDOWS:    
  968.                                             mciOpenParms.lpstrDeviceType = "avivideo";
  969.                                             mciOpenParms.lpstrElementName = fileName;
  970.                                             OpenDevice(MEDIA_VIDEO_FOR_WINDOWS);
  971.                                             wDeviceID = mciOpenParms.wDeviceID;
  972.                                             
  973.                                             f.setText(File.getName(fileName));
  974.                                             f.setWidth(0);
  975.                                             f.setHeight(0);
  976.                                             mciWindowParms.hWnd = f.getHandle();
  977.                                             
  978.                                             // Associate a window to play the AVI file
  979.                                             mciError = mciSendCommand(wDeviceID,MCI_WINDOW,MCI_OVLY_WINDOW_HWND,mciWindowParms);
  980.                                             if (mciError != 0) {
  981.                                                  printMCIError(mciError);
  982.                                                  CloseDevice();
  983.                                                  return -1;
  984.                                             }
  985.                                             
  986.                                             // Get coordinates of AVI
  987.                                             mciError = mciSendCommand(wDeviceID,MCI_WHERE,MCI_OVLY_RECT|MCI_OVLY_WHERE_DESTINATION,mciRectParms);
  988.                                             if (mciError != 0) {
  989.                                                  printMCIError(mciError);
  990.                                                  CloseDevice();
  991.                                                  return -1;
  992.                                             }
  993.                                             
  994.                                             // Resize the window to the size of the AVI
  995.                                             f.setLeft(mciRectParms.rc.left + x);
  996.                                             f.setTop(mciRectParms.rc.top + y);
  997.                                             f.setWidth(mciRectParms.rc.right - mciRectParms.rc.left + 8); // Border width = 8
  998.                                             f.setHeight(f.getHeight() + mciRectParms.rc.bottom - mciRectParms.rc.top);
  999.                                             
  1000.                                                             
  1001.                                             // Make AVI form visible
  1002.                                             f.setVisible(true);    
  1003.                                             
  1004.                                             // Start playing
  1005.                                             mciError = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY,mciPlayParms);
  1006.                                             if (mciError != 0) {
  1007.                                                 printMCIError(mciError);
  1008.                                                 CloseDevice();
  1009.                                                 return -1;
  1010.                                             }
  1011.                                             MediaPlaying = true;
  1012.                                             
  1013.                                             break;
  1014.                                             
  1015.             default                        :    break;
  1016.         }
  1017.         
  1018.         return 1;
  1019.     }
  1020.  
  1021.     public static void StopMedia (int mediaType) {
  1022.         int mciError;
  1023.         MCI_GENERIC_PARMS mciGenericParms = new MCI_GENERIC_PARMS();
  1024.  
  1025.         if (mediaType == MEDIA_CD_AUDIO) 
  1026.             OpenDevice(mediaType);
  1027.         
  1028.         // Stop Playing
  1029.         mciError = mciSendCommand(wDeviceID, MCI_STOP, 0, mciGenericParms);
  1030.  
  1031.         if (mciError != 0) {
  1032.             printMCIError(mciError);
  1033.         }
  1034.         MediaPlaying = false;
  1035.         MediaPaused = false;
  1036.         
  1037.         CloseDevice();
  1038.     }
  1039.     
  1040.             
  1041.     public static void PauseMedia(int mediaType)
  1042.     {
  1043.         int mciError;
  1044.         MCI_PLAY_PARMS mciPlayParms = new MCI_PLAY_PARMS();
  1045.         
  1046.         if (mediaType == MEDIA_CD_AUDIO)
  1047.             OpenDevice(mediaType);
  1048.         
  1049.         // Pause Playing
  1050.         mciError = mciSendCommand(wDeviceID, MCI_PAUSE, MCI_NOTIFY,mciPlayParms);
  1051.         if (mciError != 0) {
  1052.             printMCIError(mciError);
  1053.         }
  1054.         MediaPaused = true;
  1055.         MediaPlaying = false;
  1056.         
  1057.         if (mediaType == MEDIA_CD_AUDIO)
  1058.             CloseDevice();
  1059.      }
  1060.     
  1061.     
  1062.     public static void ResumeMedia(int mediaType)
  1063.     {
  1064.         int mciError;
  1065.         MCI_PLAY_PARMS mciPlayParms = new MCI_PLAY_PARMS();
  1066.         
  1067.         if (mediaType == MEDIA_CD_AUDIO)
  1068.             OpenDevice(mediaType);
  1069.         
  1070.         // Resume Playing
  1071.         if (mediaType == MEDIA_MIDI_SEQUENCER)
  1072.             mciError = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY,mciPlayParms);
  1073.         else
  1074.             mciError = mciSendCommand(wDeviceID, MCI_RESUME, MCI_NOTIFY,mciPlayParms);
  1075.         if (mciError != 0) {
  1076.             printMCIError(mciError);
  1077.         }
  1078.         MediaPaused = false;
  1079.         MediaPlaying = true;
  1080.         if (mediaType == MEDIA_CD_AUDIO)
  1081.             CloseDevice();
  1082.      }
  1083.     
  1084.  
  1085.     
  1086.     // Win32 functions  : Added using the J/Direct Call Builder
  1087.     
  1088.     public static final int MCI_OPEN = 0x0803;
  1089.     public static final int MCI_SET_TIME_FORMAT = 0x00000400;
  1090.     public static final int MCI_CLOSE = 0x0804;
  1091.     public static final int MCI_PLAY = 0x0806;
  1092.     public static final int MCI_STOP = 0x0808;
  1093.     public static final int MCI_SET = 0x080D;
  1094.     public static final int MCI_STATUS = 0x0814;
  1095.     public static final int MCI_FROM = 0x00000004;
  1096.     public static final int MCI_OPEN_ALIAS = 0x00000400;
  1097.     public static final int MCI_OPEN_ELEMENT = 0x00000200;
  1098.     public static final int MCI_OPEN_TYPE = 0x00002000;
  1099.     public static final int MCI_STATUS_ITEM = 0x00000100;
  1100.     public static final int MCI_TRACK = 0x00000010;
  1101.     public static final int MCI_CDA_STATUS_TYPE_TRACK = 0x00004001;
  1102.     public static final int MCI_STATUS_CURRENT_TRACK = 0x00000008;
  1103.     public static final int MCI_STATUS_MEDIA_PRESENT = 0x00000005;
  1104.     public static final int MCI_STATUS_NUMBER_OF_TRACKS = 0x00000003;
  1105.     public static final int MCI_FORMAT_TMSF = 10;
  1106.     public static final int MCI_OPEN_SHAREABLE = 0x00000100;
  1107.     public static final int MCI_SEQ_STATUS_PORT = 0x00004003;
  1108.     public static final int MCI_NOTIFY = 0x00000001;
  1109.     public static final int MCI_PAUSE = 0x0809;
  1110.     public static final int MCI_RESUME = 0x0855;
  1111.     public static final int MCI_OVLY_WINDOW_HWND = 0x00010000;
  1112.     public static final int MCI_WINDOW = 0x0841;
  1113.     public static final int MCI_OVLY_PUT_DESTINATION = 0x00040000;
  1114.     public static final int MCI_OVLY_RECT = 0x00010000;
  1115.     public static final int MCI_PUT = 0x0842;
  1116.     public static final int MCI_OVLY_WHERE_DESTINATION = 0x00040000;
  1117.     public static final int MCI_WHERE = 0x0843;
  1118.     public static final int MCI_STATUS_LENGTH = 0x00000001;
  1119.     public static final int MCI_STATUS_POSITION = 0x00000002;
  1120.     
  1121.     /**F
  1122.      * @dll.struct(pack=1) 
  1123.      */
  1124.     public static class MCI_GENERIC_PARMS
  1125.     {
  1126.         public int dwCallback;
  1127.     }
  1128.  
  1129.     /**
  1130.      * @dll.struct(pack=1, auto) 
  1131.      */
  1132.     public static class MCI_OPEN_PARMS
  1133.     {
  1134.         public int dwCallback;
  1135.         public int wDeviceID;
  1136.         public String lpstrDeviceType;
  1137.         public String lpstrElementName;
  1138.         public String lpstrAlias;
  1139.     }
  1140.  
  1141.     /**
  1142.      * @dll.struct(pack=1) 
  1143.      */
  1144.     public static class MCI_PLAY_PARMS
  1145.     {
  1146.         public int dwCallback;
  1147.         public int dwFrom;
  1148.         public int dwTo;
  1149.     }
  1150.  
  1151.     /**
  1152.      * @dll.struct(pack=1) 
  1153.      */
  1154.     public static class MCI_SET_PARMS
  1155.     {
  1156.         public int dwCallback;
  1157.         public int dwTimeFormat;
  1158.         public int dwAudio;
  1159.     }
  1160.  
  1161.     /**
  1162.      * @dll.struct(pack=1) 
  1163.      */
  1164.     public static class MCI_STATUS_PARMS
  1165.     {
  1166.         public int dwCallback;
  1167.         public int dwReturn;
  1168.         public int dwItem;
  1169.         public int dwTrack;
  1170.     }
  1171.  
  1172.     /**
  1173.      * @dll.struct(pack=1) 
  1174.      */
  1175.     public static class MCI_SEQ_SET_PARMS
  1176.     {
  1177.         public int dwCallback;
  1178.         public int dwTimeFormat;
  1179.         public int dwAudio;
  1180.         public int dwTempo;
  1181.         public int dwPort;
  1182.         public int dwSlave;
  1183.         public int dwMaster;
  1184.         public int dwOffset;
  1185.     }
  1186.     
  1187.     /**
  1188.      * @dll.struct(pack=1, auto) 
  1189.      */
  1190.     public static class MCI_OVLY_WINDOW_PARMS
  1191.     {
  1192.         public int dwCallback;
  1193.         public int hWnd;
  1194.         public int nCmdShow;
  1195.         public String lpstrText;
  1196.     }
  1197.     
  1198.     
  1199.     /**
  1200.      * @dll.struct(pack=1) 
  1201.      */
  1202.     public static class MCI_OVLY_RECT_PARMS
  1203.     {
  1204.         public int dwCallback;
  1205.         public com.ms.win32.RECT rc;
  1206.     }
  1207.         
  1208.     /**
  1209.      * @dll.import("WINMM",auto) 
  1210.      */
  1211.     public static native int mciSendCommand(int mciId, int uMsg, int dwParam1, int dwParam2);
  1212.  
  1213.     /**
  1214.      * @dll.import("WINMM",auto) 
  1215.      */
  1216.     public static native int mciSendCommand(int mciId, int uMsg, int dwParam1, Object dwParam2);
  1217.  
  1218.     /**
  1219.      * @dll.import("WINMM", auto) 
  1220.      */
  1221.     public static native boolean mciGetErrorString(int mcierr, StringBuffer pszText, int cchText);
  1222.  
  1223.     
  1224. }
  1225.