Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8116065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:41:45+00:00 2026-06-06T03:41:45+00:00

JMF provides a class MediaPlayer which can be used as a full-featured player. However,

  • 0

JMF provides a class MediaPlayer which can be used as a full-featured player. However, I can’t find a way to play an audio file. Some snippets of the code used.

import javax.media.bean.playerbean.MediaPlayer;

    // ....
    MediaPlayer mp = new MediaPlayer();
    mp.setMediaLocation(location of file);  // <- syntax error!
    mp.start();

But it doesn’t work. Eclipse shows this error:

Syntax error on token "setMediaLocation", Identifier expected after this token

..on setMediaLocation() method.

Can someone tell me how to use MediaPlayer class to play audio file? and what is wrong in my coding?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:41:47+00:00Added an answer on June 6, 2026 at 3:41 am

    You do not literally have ..setMediaLocation(location of file); in the source do you? I thought that was paraphrased.

    In that case, the answer is to supply an argument to the setMediaLocation() method. The docs. specify a String or MediaLocator instance.

    I avoid using String instances to represent file or URL based sources. If a method needs a File or URL – give it a File or URL. That leaves the best option as a MediaLocator(URL). Here is how it might go. First we need a URL – there are a number of different ways of getting one, depending on what the source of the URL is. E.G. the internet, a file on the local file-system, or an embedded resource in a Jar delivered with the app. The last two might be something like:

    File based URL

    File mediaFile = new File("user.mp3");
    URL mediaURL = mediaFile.toURI().toURL();
    // ...
    

    Embedded resource URL

    URL mediaURL = this.getClass().getResource("/path/to/our.mp3");
    // ...
    

    Once there is a mediaURL instance, we can create a locator and use it in the method.

    Using the URL

    MediaLocator mediaLocator = new MediaLocator(mediaURL);
    MediaPlayer mp = new MediaPlayer();
    mp.setMediaLocation(mediaLocator); 
    // ...
    

    General tips

    1. JMF is an abandoned API.
    2. Since you seem interested only in audio, look to use Java Sound. It can play audio samples just fine, is part of core Java, and with a small part of the JMF, can play MP3 format (see link for details).
    3. You seem new to the abandoned API being used, Eclipse and debugging. Perhaps you should focus on simpler things for the moment. Media handling is an advanced topic.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Language: Java It is used in addition: JMF Below is the code (without the
I'm building a video player in pure Java around JMF, with completely custom UI
I want to capture and stream audio using JMF 2.1.1e in RTP format. I
I am using Java JMF to play a MPEG video with sound. I want
I know JMF needs to be used to deal with video, but the JMF
I want play compressed audio files. I want to know how to specify the
How can you capture Video using Java ? You have to use JMF ?
I've been struggling to find a decent RTP stack implementation for Java . JMF
which are the jars used to record video from the list of jar files
I'm trying to use JMF (Java Media Framework) to play a video. I've tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.