A simple media player problem

Hi there,
The following code is a simple media player applet. Now I try to change it to an application.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.lang.String;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;
import java.util.Properties;
import javax.media.*;
public class SimplePlayerApplet extends Applet implements ControllerListener {
// media Player
Player player = null;
// component in which video is playing
Component visualComponent = null;
// controls gain, position, start, stop
Component controlComponent = null;
// displays progress during download
Component progressBar = null;
boolean firstTime = true;
long CachingSize = 0L;
Panel panel = null;
int controlPanelHeight = 0;
int videoWidth = 0;
int videoHeight = 0;
* Read the applet file parameter and create the media
* player.
public void init() {
          //$ System.out.println("Applet.init() is called");
          setLayout(null);
          setBackground(Color.white);
          panel = new Panel();
          panel.setLayout( null );
          add(panel);
          panel.setBounds(0, 0, 320, 240);
          // input file name from html param
          String mediaFile = null;
          // URL for our media file
          MediaLocator mrl = null;
          URL url = null;
          // Get the media filename info.
          // The applet tag should contain the path to the
          // source media file, relative to the html page.
          if ((mediaFile = getParameter("FILE")) == null)
          Fatal("Invalid media file parameter");
          try {
          url = new URL(getDocumentBase(), mediaFile);
          mediaFile = url.toExternalForm();
          } catch (MalformedURLException mue) {
          try {
          // Create a media locator from the file name
          if ((mrl = new MediaLocator(mediaFile)) == null)
               Fatal("Can't build URL for " + mediaFile);
          // Create an instance of a player for this media
          try {
                    player = Manager.createPlayer(mrl);
          } catch (NoPlayerException e) {
                    System.out.println(e);
                    Fatal("Could not create player for " + mrl);
          // Add ourselves as a listener for a player's events
          player.addControllerListener(this);
          } catch (MalformedURLException e) {
          Fatal("Invalid media file URL!");
          } catch (IOException e) {
          Fatal("IO exception creating player for " + mrl);
* Start media file playback. This function is called the
* first time that the Applet runs and every
* time the user re-enters the page.
public void start() {
     //$ System.out.println("Applet.start() is called");
// Call start() to prefetch and start the player.
if (player != null)
     player.start();
* Stop media file playback and release resource before
* leaving the page.
public void stop() {
     //$ System.out.println("Applet.stop() is called");
if (player != null) {
player.stop();
player.deallocate();
public void destroy() {
     //$ System.out.println("Applet.destroy() is called");
          player.close();
* This controllerUpdate function must be defined in order to
* implement a ControllerListener interface. This
* function will be called whenever there is a media event
public synchronized void controllerUpdate(ControllerEvent event) {
     // If we're getting messages from a dead player,
     // just leave
     if (player == null)
     return;
     // When the player is Realized, get the visual
     // and control components and add them to the Applet
     if (event instanceof RealizeCompleteEvent) {
     if (progressBar != null) {
               panel.remove(progressBar);
               progressBar = null;
     int width = 320;
     int height = 0;
     if (controlComponent == null)
          if (( controlComponent =
          player.getControlPanelComponent()) != null) {
          controlPanelHeight = controlComponent.getPreferredSize().height;
          panel.add(controlComponent);
          height += controlPanelHeight;
     if (visualComponent == null)
          if (( visualComponent =
          player.getVisualComponent())!= null) {
          panel.add(visualComponent);
          Dimension videoSize = visualComponent.getPreferredSize();
          videoWidth = videoSize.width;
          videoHeight = videoSize.height;
          width = videoWidth;
          height += videoHeight;
          visualComponent.setBounds(0, 0, videoWidth, videoHeight);
     panel.setBounds(0, 0, width, height);
     if (controlComponent != null) {
               controlComponent.setBounds(0, videoHeight,
                         width, controlPanelHeight);
               controlComponent.invalidate();
     } else if (event instanceof CachingControlEvent) {
     if (player.getState() > Controller.Realizing)
               return;
     // Put a progress bar up when downloading starts,
     // take it down when downloading ends.
     CachingControlEvent e = (CachingControlEvent) event;
     CachingControl cc = e.getCachingControl();
     // Add the bar if not already there ...
     if (progressBar == null) {
     if ((progressBar = cc.getControlComponent()) != null) {
          panel.add(progressBar);
          panel.setSize(progressBar.getPreferredSize());
          validate();
     } else if (event instanceof EndOfMediaEvent) {
     // We've reached the end of the media; rewind and
     // start over
     player.setMediaTime(new Time(0));
     player.start();
     } else if (event instanceof ControllerErrorEvent) {
     // Tell TypicalPlayerApplet.start() to call it a day
     player = null;
     Fatal(((ControllerErrorEvent)event).getMessage());
} else if (event instanceof ControllerClosedEvent) {
     panel.removeAll();
void Fatal (String s) {
     // Applications will make various choices about what
     // to do here. We print a message
          System.err.println("FATAL ERROR: " + s);
          throw new Error(s); // Invoke the uncaught exception
               // handler System.exit() is another
               // choice.
The change I've made:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.lang.String;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;
import java.util.Properties;
import javax.media.*;
import javax.swing.*;
public class MoviePlayer extends JFrame implements ControllerListener {
// media Player
Player player = null;
// component in which video is playing
Component visualComponent = null;
// controls gain, position, start, stop
Component controlComponent = null;
// displays progress during download
Component progressBar = null;
boolean firstTime = true;
long CachingSize = 0L;
JPanel panel = null;
int controlPanelHeight = 0;
int videoWidth = 0;
int videoHeight = 0;
* Read the applet file parameter and create the media
* player.
public MoviePlayer() {
     FlowLayout layout = new FlowLayout();
          setTitle("Media Application");
          setDefaultLookAndFeelDecorated(true);
          Container mainWindow = getContentPane();
     //$ System.out.println("Applet.init() is called");
          setBackground(Color.white);
          panel = new JPanel();
          panel.setBounds(0, 0, 320, 240);
          mainWindow.add(panel);
          // input file name from html param
          String mediaFile = null;
          // URL for our media file
          MediaLocator mrl = null;
          URL url = null;
          // Get the media filename info.
          // The applet tag should contain the path to the
          // source media file, relative to the html page.
          mediaFile = "abc.avi";
          try {
          url = new URL(mediaFile);
          mediaFile = url.toExternalForm();
          } catch (MalformedURLException mue) {
          try {
          // Create a media locator from the file name
          if ((mrl = new MediaLocator(mediaFile)) == null)
                    Fatal("Can't build URL for " + mediaFile);
          // Create an instance of a player for this media
          try {
                    player = Manager.createPlayer(mrl);
          } catch (NoPlayerException e) {
                    System.out.println(e);
                    Fatal("Could not create player for " + mrl);
          // Add ourselves as a listener for a player's events
          player.addControllerListener(this);
          } catch (MalformedURLException e) {
          Fatal("Invalid media file URL!");
          } catch (IOException e) {
          Fatal("IO exception creating player for " + mrl);
* Start media file playback. This function is called the
* first time that the Applet runs and every
* time the user re-enters the page.
public void start() {
     //$ System.out.println("Applet.start() is called");
// Call start() to prefetch and start the player.
if (player != null)
     player.start();
* Stop media file playback and release resource before
* leaving the page.
public void stop() {
     //$ System.out.println("Applet.stop() is called");
if (player != null) {
player.stop();
player.deallocate();
public void destroy() {
     //$ System.out.println("Applet.destroy() is called");
          player.close();
* This controllerUpdate function must be defined in order to
* implement a ControllerListener interface. This
* function will be called whenever there is a media event
public synchronized void controllerUpdate(ControllerEvent event) {
     // If we're getting messages from a dead player,
     // just leave
     if (player == null)
     return;
     // When the player is Realized, get the visual
     // and control components and add them to the Applet
     if (event instanceof RealizeCompleteEvent) {
     if (progressBar != null) {
               panel.remove(progressBar);
               progressBar = null;
     int width = 320;
     int height = 0;
     if (controlComponent == null)
          if (( controlComponent =
          player.getControlPanelComponent()) != null) {
          controlPanelHeight = controlComponent.getPreferredSize().height;
          panel.add(controlComponent);
          height += controlPanelHeight;
     if (visualComponent == null)
          if (( visualComponent =
          player.getVisualComponent())!= null) {
          panel.add(visualComponent);
          Dimension videoSize = visualComponent.getPreferredSize();
          videoWidth = videoSize.width;
          videoHeight = videoSize.height;
          width = videoWidth;
          height += videoHeight;
          visualComponent.setBounds(0, 0, videoWidth, videoHeight);
     panel.setBounds(0, 0, width, height);
     if (controlComponent != null) {
               controlComponent.setBounds(0, videoHeight,
                         width, controlPanelHeight);
               controlComponent.invalidate();
     } else if (event instanceof CachingControlEvent) {
     if (player.getState() > Controller.Realizing)
               return;
     // Put a progress bar up when downloading starts,
     // take it down when downloading ends.
     CachingControlEvent e = (CachingControlEvent) event;
     CachingControl cc = e.getCachingControl();
     // Add the bar if not already there ...
     if (progressBar == null) {
     if ((progressBar = cc.getControlComponent()) != null) {
               panel.add(progressBar);
               panel.setSize(progressBar.getPreferredSize());
               validate();
     } else if (event instanceof EndOfMediaEvent) {
     // We've reached the end of the media; rewind and
     // start over
     player.setMediaTime(new Time(0));
     player.start();
     } else if (event instanceof ControllerErrorEvent) {
     // Tell TypicalPlayerApplet.start() to call it a day
     player = null;
     Fatal(((ControllerErrorEvent)event).getMessage());
} else if (event instanceof ControllerClosedEvent) {
     panel.removeAll();
void Fatal (String s) {
     // Applications will make various choices about what
     // to do here. We print a message
          System.err.println("FATAL ERROR: " + s);
          throw new Error(s); // Invoke the uncaught exception
               // handler System.exit() is another
               // choice.
public static void main(String[] args){
     MoviePlayer view = new MoviePlayer();
          view.setSize(600,250);
          view.setVisible(true);
          view.addWindowListener(new WindowAdapter () {
               public void windowClosing (WindowEvent e) {
                    System.exit(0);
It does compile, but when I run it, it prints the following error message:
javax.media.NoPlayerException: Cannot find a Player for :abc.avi
FATAL ERROR: Could not create player for abc.avi
Exception in thread "main" java.lang.Error: Could not create player for abc.avi
at MoviePlayer.Fatal(MoviePlayer.java:257)
at MoviePlayer.<init>(MoviePlayer.java:123)
at MoviePlayer.main(MoviePlayer.java:263)
Press any key to continue...
Any advice?
Thank you

Hi,
That is due to the way MediaLocator excepts the filename to be formed. add the following line:
// Get the media filename info.
// The applet tag should contain the path to the
// source media file, relative to the html page.
mediaFile = "abc.avi";
//HERE'S THE LINE YOU NEED TO ADD
if ( mediaFile.indexOf( ":" ) < 3 ) mediaFile = "file:" + mediaFile;It formats the filename properly. Also make sure the abc.avi file is in the current directory.

Similar Messages

  • Device screen not turning off + Media Player Problems

    My screen does not turn off, I checked the settings in screen/keyboard and they are set but don't seem to work. This is causing my battery to drain.
    Also, I am having intermittent media player problems.
    Suggestions?

    Hi and Welcome to the Community!
    I recommend that you attempt to boot into Safe Mode:
    KB17877 How to start a BlackBerry smartphone in Safe Mode
    It may take you multiple attempts to get the ESC key sequence (press/release/hold) correct, so be patient. When successfully into Safe Mode, think carefully...what happened just before this behavior started? A new app? An update? A Theme? Something else? Think carefully as the smallest change could be causal...and attempt to undo whatever that was.
    Good luck and let us know!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Safari/Windows Media Player problem.

    I have a bit of a problem at the moment with viewing video content on some sites - when I click the link/button/whatever this message appears -
    "Safari can't display content on this page
    Some content on this page requires an Internet plug-in that Safari doesn’t support. The application “Windows Media Player” may be able to display this content. Would you like to try?"
    When I do try WMP, it opens ok, tries to play it, then gives me this message-
    "The file name, directory name, or volume label syntax is incorrect"

    Do you also have Flip4Mac installed?
    If not, Microsoft is no longer supporting Windows Media Player for OS X but Flip4Mac will continue to be supported which adds a plugin for Safari and other browsers that should work.
    http://www.microsoft.com/mac/otherproducts/otherproducts.aspx?pid=windowsmedia

  • Windows Media Player Problem after upgrading to 8.1

    Hello, I upgraded my Yoga 13 from windows 8.0 to Windows 8.1 and now Media player 12 gives me this error message:
    "Windows Media Player cannot play the file. The Player might not support the file type or might not support the codec that was used to compress the file."
    I had Divx Codecs installed prior to upgrading so I tried uninstalling them which did not work, then I tried reinstalling Media Player which did not work either.
    Any ideas??
    Solved!
    Go to Solution.

    This problem is actually caused by the Conexant audio driver. Something about the Windows 8.1 installation screws up the this driver installation.  The fix is to reinstall the Conexant audio driver from the Lenovo driver page:
    http://support.lenovo.com/en_US/downloads/detail.page?DocID=DS032590

  • Windows Media player problem after 4.2.2

    Since the KitKat update WIndows Media Player won't show my phone so I can't sync my music.there.
    Yes I know I could use Media Go - but WMP is a LOT easier to use.
    I can get the Z1 through My Computer ok.
    My Xperia Z tablet with KitKat works fine with Windows Media Player so why doesn't the Z1? Using same cable / USB 2.0 port
    This is annoying me so I hope it's a quick answer.
    I've reinstalled the driver in Device Manager.
    Much appreciated
    Solved!
    Go to Solution.

    Well I seem to have sorted it using the Z2 driver mentioned in another post.
    WIll try this on my daughters laptop / Xperia Z as she has the same problem since the Kitkat update.

  • Help needed with N80 media player problem

    Hi,
    My other half owns a N80 and he deleted something on his phone and now when he goes into media player it says there are no tracks. All the songs are in his track library but you have to manually select which songs to play instead of playing them all.
    Is there a way of getting the media player to find the songs?
    Thanks, Carrie.

    04-Sep-2006
    01:08 PM
    adamski wrote:
    It should be there, the options I have are:
    Open
    Track Downloads
    Play
    Update Music Library
    Music Library details
    Help
    Exit
    so it should be there. Get your hands and eyes on it and if you find it, give him a swift clip round the noggin !!!
    Ad.
    I don't have these options either. I have wondered for ages how to use the jukebox thingy
    Is that an N95 in your pocket or are you just pleased to see me?!?
    Life's too important to take seriously.
    Nokias I've owned 3210, 3310, 6100, 7650, 6600, 6680, 6630, N80, N95
    I'm a 26 year old boy BTW

  • Windows Media Player Problems and MacBook Pro

    Hi!
    I installed the Windows Media Player 9 for Mac on my MacBook Pro, used it a couple times and now it just won't work. I have deleted it and re-installed it several times and the same thing happens. WMP starts to load and then i get an error message saying the application ended abruptly and other apps and OS have not been affected. I then sent the report to Apple by pressing the "Report..." button. So, now i just want to get rid of the program and all its files. I deleted the WMP folder and it's preference files, but when i initially installed the program, the VISE installer said it installed 510 files to my HD. Really?
    My 2 questions are:
    1- what are all the files I have to delete to totally get this application and all its files off my system? I want a clean uninstall as possible.
    2- have i done any potential harm to my MacBook Pro? Any diagnostic checks I should run?
    Thanks!
    MacBook Pro   Mac OS X (10.4.6)  

    1: Check /Library/Application Support/Microsoft/ and /Library/Internet Plugins/
    2: probably not, but using OnyX once in a while is a good idea anyways.
    http://versiontracker.com/dyn/moreinfo/macosx/20070

  • Windows Media Player problem

    I use Windows Media Player as my default player.  Starting today, any video (whether from a DVD or already existing on my computer) comes up in a tiny window.  The media player screen itself comes up filling the screen as always, but the viewing area is only 3 or 4 inches.  Clicking on the buttons in upper right to expand to full screen or the middle button has no effect.  Normally, the picture comes up much larger, filling the media player framework completely.  I can click the media player control at lower right to expand to full screen, eliminating the media player frame, but I want it to come up like it always has.  Can anyone help?

    Not really a "Apple SU for Windows" question.
    Flip4Mac or VLC or something probably.

  • N95 firmware v12 and media player problem

    Hi,
    In firmware version 10, when I want to go in Media Player, I pressed and holded shortcut key for once then gone in Media Player. But now, In firmware version 12, for going in to Media Player, Sometimes I should press and hold shortcut key for ONCE and sometimes for TWOICE !!!
    Why ???Message Edited by zoologist1 on 12-Aug-200707:42 PM

    This is a known issue which should be resolved in the next release of the N95 firmware.
    Regards,
    Edward

  • Media Player Problem playing only one song at a time

    Recently acquired a BB Curve 8330 (OS 4.5.0.127) running on a Bell Enterprise server.  I bought a SanDisk 16G Media Card.  The card is formatted, the songs are there (about 20 albums)  I can view, scroll, choose shuffle, choose an album, choose a artist or any other option.  No matter what I try, it will only play one song at a time.  Once the song plays, it just stops and stays at the end of the song.  Periodically, the entire device will shut down and restart.  I saw somewhere else in the forum to pull the battery, wait 1-2 minutes, didn't work.  There was also a post to try to downgrade the software from 4.5.0.127, but really, is that necessary?
    Is there a fix, patch, upgrade, or other I can try rather than going backwards?
    Please help.  Really frustrating.

    I was having the same problem.  I found out the CD's that I ripped were not in MP3 format they were in windows media audio format.  I was able to load them to my phone and they would play one at a time or when a song got to the end it would restart my phone.  Replaced WMA files with MP3 files and it fixed the problem. Hope this helps.

  • HELP!!Nokia 6280 media player problem

    I need help since i can't use the forward and rewind function when i play my videos..anyone got an answer??

    if you hold down next track arrow it skips forward 5 seconds at a time but thats it.......

  • If you're having problems updating firmware and have Windows Media Player 11 B

    I've seen a number of problems with people updating their firmware with WMP installed and it turns out that's the problem. WMP has a bug in it that will not allow the firmware update to recognize the player. So, here's what to do to roll back to a previous version:
    These instructions will only work for Windows XP
    You must be logged on as an administrator or a member of the Administrators group to perform the following procedure.
    . Disconnect any portable music or video devices that might be attached to your computer.
    2. Click Start, and then click Control Panel.
    3. In the Category View of Control Panel, click Add or Remove Programs, and then click Remove a program.
    4. Click Windows Media Player , and then click Remove.
    If Windows Media Player is not displayed in the list of currently installed programs, then try the following:
    . At the top of the list, select the Show updates check box.
    2. In the Windows XP - Software Updates section, click Windows Media Player , and then click Change/Remove.
    5. In each of the two confirmation dialog boxes that appear, click OK.
    6. When the rollback process is complete (it might take several minutes), click Restart.
    7. Click Start, and then click Control Panel.
    8. In the Category View of Control Panel, click Add or Remove Programs, and then click Remove a program.
    9. Click Windows Media Format Runtime, and then click Remove.
    If Windows Media Format Runtime is not displayed in the list of currently installed programs, then try the following:
    . At the top of the list, select the Show updates check box.
    2. In the Windows XP - Software Updates section, click Windows Media Format Runtime, and then click Change/Remove.
    If you installed a non-US English version of Windows Media Player , the instructions in the dialog boxes that are mentioned in steps 9, 0, and might appear in English.
    0. In the first confirmation dialog box that appears, click OK.
    . In the second confirmation dialog box that appears, select the Do you want to continue with the rollback? check box, and then click OK.
    2. When the rollback process is complete (it might take several minutes to complete), click Restart.
    3. Click Start, and then click Control Panel.
    4. In the Category View of Control Panel, click Add or Remove Programs, and then click Remove a program.
    5. Click Microsoft User-Mode Driver Framework Feature Pack .0.0, and then click Remove.
    6. Follow the instructions that appear in the Software Update Removal Wizard.
    If the Wudf0000 confirmation dialog box appears, click Yes to continue. When the software removal process is complete (it might take several minutes to complete), click Finish.
    If you are still having problems and all else fails, do a System Restore to before WMP was installed.
    *Note: If you remove Windows Media Player and the Windows Media Format Runtime, and then encounter error C00D27D ("A problem has occurred in the Digital Rights Management component. Contact Microsoft product support, you might be able to resolve the problem by installing the Windows Media Format 9.5 Runtime. For information about installing the Runtime, in the Microsoft Knowledge Base, see article 8922, "Update for Windows Media Digital Rights Management-enabled players."
    **You might not be able to roll back to a previous version of the Player if the hidden folder $NtUninstallwmp$ is deleted from your computer. Some non-Microsoft programs (such as CCleaner) delete this folder in an attempt to remove unwanted files from your computer.
    More information here:
    http://www.microsoft.com/windows/win...ionofthePlayer
    Some people have found these instructions to be a solution to the "Player Not Connected" Error when trying to update the firmware. (Your mileage may vary)
    Note to Mods: This would make a nice sticky

    OK. I've been having this problem and have probably read every post there is on the net concerning it. But it doesn't seem to be only a Media Player problem. I was only running Media Player 0 when it happened to me. I found the solution somewhere, I can't remember where, but it worked for me and it was easy.
    Here's what you do:
    . Download BOTH ZenXtra_PCFW_LA__20_08.exe and enXtraP4SAudible_PCFW_LB_2_0_03.exe
    2. Connect the Zen Xtra to your PC.
    3. Run ZenXtra_PCFW_LA__20_08.exe. When the window comes up and says that your device is not connected DON'T do ANYTHING! Just leave it there.
    4. Now run ZenXtraP4SAudible_PCFW_LB_2_0_03.exe
    5. It told me that I already had this version on my device did I still want to load it's I said yes and it went through the whole upgrade and now it works fine.

  • Win Media Player from JMF...

    Hi,
    I am new to JMF. I am currently developing a p2p based video streaming project and would like to invoke Win Media Player or Flash Movie Playre from the Java app..
    Pleasen help / advice / suggest...
    Thank you.
    Salil.Siddhaye

    this code may help it is sun sample code
    * @(#)SimplePlayerApplet.java     1.2 01/03/13
    * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
    * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
    * modify and redistribute this software in source and binary code form,
    * provided that i) this copyright notice and license appear on all copies of
    * the software; and ii) Licensee does not utilize the software in a manner
    * which is disparaging to Sun.
    * This software is provided "AS IS," without a warranty of any kind. ALL
    * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
    * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
    * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
    * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
    * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
    * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
    * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
    * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
    * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
    * POSSIBILITY OF SUCH DAMAGES.
    * This software is not designed or intended for use in on-line control of
    * aircraft, air traffic, aircraft navigation or aircraft communications; or in
    * the design, construction, operation or maintenance of any nuclear
    * facility. Licensee represents and warrants that it will not use or
    * redistribute the Software for such purposes.
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.String;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.io.IOException;
    import java.util.Properties;
    import javax.media.*;
    //import com.sun.media.util.JMFSecurity;
    * This is a Java Applet that demonstrates how to create a simple
    * media player with a media event listener. It will play the
    * media clip right away and continuously loop.
    * <!-- Sample HTML
    * <applet code=SimplePlayerApplet width=320 height=300>
    * <param name=file value="sun.avi">
    * </applet>
    * -->
    public class SimplePlayerApplet extends Applet implements ControllerListener {
    // media Player
    Player player = null;
    // component in which video is playing
    Component visualComponent = null;
    // controls gain, position, start, stop
    Component controlComponent = null;
    // displays progress during download
    Component progressBar = null;
    boolean firstTime = true;
    long CachingSize = 0L;
    Panel panel = null;
    int controlPanelHeight = 0;
    int videoWidth = 0;
    int videoHeight = 0;
    * Read the applet file parameter and create the media
    * player.
    public void init() {
         //$ System.out.println("Applet.init() is called");
         setLayout(null);
         setBackground(Color.white);
         panel = new Panel();
         panel.setLayout( null );
         add(panel);
         panel.setBounds(0, 0, 320, 240);
         // input file name from html param
         String mediaFile = "The Departed CD1.avi";
         // URL for our media file
         MediaLocator mrl = null;
         URL url = null;
         // Get the media filename info.
         // The applet tag should contain the path to the
         // source media file, relative to the html page.
         if ((mediaFile = getParameter("FILE")) == null)
         Fatal("Invalid media file parameter");
         try {
         url = new URL(getDocumentBase(), mediaFile);
         mediaFile = url.toExternalForm();
         } catch (MalformedURLException mue) {
         try {
         // Create a media locator from the file name
         if ((mrl = new MediaLocator(mediaFile)) == null)
              Fatal("Can't build URL for " + mediaFile);
         try {
              JMFSecurity.enablePrivilege.invoke(JMFSecurity.privilegeManager,
                                  JMFSecurity.writePropArgs);
              JMFSecurity.enablePrivilege.invoke(JMFSecurity.privilegeManager,
                                  JMFSecurity.readPropArgs);
              JMFSecurity.enablePrivilege.invoke(JMFSecurity.privilegeManager,
                                  JMFSecurity.connectArgs);
         } catch (Exception e) {}
         // Create an instance of a player for this media
         try {
              player = Manager.createPlayer(mrl);
         } catch (NoPlayerException e) {
              System.out.println(e);
              Fatal("Could not create player for " + mrl);
         // Add ourselves as a listener for a player's events
         player.addControllerListener(this);
         } catch (MalformedURLException e) {
         Fatal("Invalid media file URL!");
         } catch (IOException e) {
         Fatal("IO exception creating player for " + mrl);
         // This applet assumes that its start() calls
         // player.start(). This causes the player to become
         // realized. Once realized, the applet will get
         // the visual and control panel components and add
         // them to the Applet. These components are not added
         // during init() because they are long operations that
         // would make us appear unresposive to the user.
    * Start media file playback. This function is called the
    * first time that the Applet runs and every
    * time the user re-enters the page.
    public void start() {
         //$ System.out.println("Applet.start() is called");
    // Call start() to prefetch and start the player.
    if (player != null)
         player.start();
    * Stop media file playback and release resource before
    * leaving the page.
    public void stop() {
         //$ System.out.println("Applet.stop() is called");
    if (player != null) {
    player.stop();
    player.deallocate();
    public void destroy() {
         //$ System.out.println("Applet.destroy() is called");
         player.close();
    * This controllerUpdate function must be defined in order to
    * implement a ControllerListener interface. This
    * function will be called whenever there is a media event
    public synchronized void controllerUpdate(ControllerEvent event) {
         // If we're getting messages from a dead player,
         // just leave
         if (player == null)
         return;
         // When the player is Realized, get the visual
         // and control components and add them to the Applet
         if (event instanceof RealizeCompleteEvent) {
         if (progressBar != null) {
              panel.remove(progressBar);
              progressBar = null;
         int width = 320;
         int height = 0;
         if (controlComponent == null)
              if (( controlComponent =
              player.getControlPanelComponent()) != null) {
              controlPanelHeight = controlComponent.getPreferredSize().height;
              panel.add(controlComponent);
              height += controlPanelHeight;
         if (visualComponent == null)
              if (( visualComponent =
              player.getVisualComponent())!= null) {
              panel.add(visualComponent);
              Dimension videoSize = visualComponent.getPreferredSize();
              videoWidth = videoSize.width;
              videoHeight = videoSize.height;
              width = videoWidth;
              height += videoHeight;
              visualComponent.setBounds(0, 0, videoWidth, videoHeight);
         panel.setBounds(0, 0, width, height);
         if (controlComponent != null) {
              controlComponent.setBounds(0, videoHeight,
                             width, controlPanelHeight);
              controlComponent.invalidate();
         } else if (event instanceof CachingControlEvent) {
         if (player.getState() > Controller.Realizing)
              return;
         // Put a progress bar up when downloading starts,
         // take it down when downloading ends.
         CachingControlEvent e = (CachingControlEvent) event;
         CachingControl cc = e.getCachingControl();
         // Add the bar if not already there ...
         if (progressBar == null) {
         if ((progressBar = cc.getControlComponent()) != null) {
              panel.add(progressBar);
              panel.setSize(progressBar.getPreferredSize());
              validate();
         } else if (event instanceof EndOfMediaEvent) {
         // We've reached the end of the media; rewind and
         // start over
         player.setMediaTime(new Time(0));
         player.start();
         } else if (event instanceof ControllerErrorEvent) {
         // Tell TypicalPlayerApplet.start() to call it a day
         player = null;
         Fatal(((ControllerErrorEvent)event).getMessage());
    } else if (event instanceof ControllerClosedEvent) {
         panel.removeAll();
    void Fatal (String s) {
         // Applications will make various choices about what
         // to do here. We print a message
         System.err.println("FATAL ERROR: " + s);
         throw new Error(s); // Invoke the uncaught exception
                   // handler System.exit() is another
                   // choice.
    take care add the video to the same path where the code is saved
    hope that will help you

  • Problem with "play to device" on windows media player

    Hello, I'm having a problem with the play to device feature of windows media player.  I am trying to use it to play music files to my T.V.  It works fine if i try to play a single file or a small number of files (50 or so), but if I try to play
    my entire playlist (346 songs, if it matters)in this way or a large number of random songs, nothing happens.  No error messages or freezes either, it's as if i never clicked play.  I thought this might be a limitation with the t.v. or my network
    (im doing this via wi-fi) but when i tried this using windows explorer instead of windows media player it worked just fine, and this was with all the music on my computer which is about 3000 songs.  Therefore, i know this is a problem with windows media
    player and not my t.v., network or computer.  This is a problem because i don't want to play all my music, just my playlist.  Short of making a separate folder with duplicate files in it for each and every playlist i want to play in this manner(which
    is not only time consuming and tedious but takes up space on my hard drive)  how do i remove this limitation or otherwise get around it?  Thanks!
    P.S.  Out of curiosity, why does this limitation exist and what causes it?

     when i tried this using windows explorer instead of windows media player it worked just fine, and this was with all the music on my computer which is about 3000 songs.  
    Hi,
    According to your description,you said that you used windows explorer.Did you share 3000 songs with your TV?
    If so,I think this method is different with "play to" feature.
    Also,we haven't found any limitation with Windows media player.
    Regards,
    Kelvin Xu
    TechNet Community Support

  • Problems with Ipod and Windows Media Player PLEASE HELP

    Ok i am not sure if this is the correct forum or not but i am having a problem. I have a Windows computer (Yes a windows computer please dont everyone yell at me) and i have a new ipod 30 gig video. Ok well when i put itunes on it changes all my music on my computer gets changed to AAC format and i cannot play music in windows media player. Ok well that is not my big issue. I make videos for church using windows movie maker and i cannot import music because nothing windows can recognize Itunes format which is AAC. well is there anyway so i can use itunes and still use WIndows Media Player and Windows Movie Maker... Any info will be greatly appreciated. THANKS ALL

    I believe Quicktime Pro (which is available for Windoze) is capable of opening any WMP files and then you just export it as iPod format. That is how I get video onto the iPod. The Music and Videos all can be placed onto your iPod through iTunes.
    So, if you are creating videos in your program, and want them on your iPod, then that is how you can do it.
    Videos on your iPod have nothing to do with the formatting of your music. But, as the earlier post stated, change your prefs in iTunes to import as MP3. But, your videos HAVE to be in MP4 or M4V format to work on the iPod.
    Good luck... and I'm a j3susfreak too

Maybe you are looking for

  • IPhoto 11 window won't open, only have full screen view

    After I upgraded, the iphoto window would not come up. The menu bar at the top is active, and I am able to access my photos from Full Screen View. But when I toggle back, and close full screen, everything closes... Any suggestions? Thank you!

  • Lightroom Crashes when Using Slideshow after OS X Upgrade to Mavericks 10.9.5 - Can anyone please help?

    I have done a routine OS X upgrade (mac) yesterday to version 10.9.5.  Since then, Lightroom (4.4) has crashed more times than I can count. It is impossible to access the Slideshow Module as it crashes right away.  Lightroom is completely useless at

  • Opening Pioneer DVDRW drive door without power

    I have a problem with my Pioneer DVDRW drive on my G5. When it closes with a disk in it it sounds like a mixmaster. I suspect I accidently placed one of the clear plastic protectors that come with a new stack of DVDs together with the disk in the dri

  • How do you convert Raw files into jpeg.

      I have never shot in Raw before and I have a huge project due tomorrow. I need help Asap. What is the easiest way to convert Raw files into jpeg, can Light Room convert the files. I have tried so many different ways and nothing seems to work.

  • Meaning of Error!!!

    Please tell me what is the meaning of this error "For type "P", a length specification from 1 to 16 40 P". Thanks & Regards Santhosh