We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,619 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion
Page 2 of Article: Simple Sound Player...
Simple Sound Player Goal The goal of this assignment is to implement a simple sound player. The application has been partially implemented, and you need to complete the missing bits. When you open the project, you will see the class structure depicted below. Three of the classes are fully implemented…

public Track(File soundFile)

public Player()
{
    playList = new PlayList("audio");
    track = new Track();
}

The syntax of an operation to create a new object is new ClassName(parameter-list)

How do I put (File soundFile) as the parameters in new Track()?

SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Read the API doc for the Track class to see what parameters it takes in its constructor.

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

The reason why you get errors you don't understand, is because you didn't bother to try and understand what was going on, you just copy-pasted the codebase out of this thread without knowing anything about what files the OP had on his system.

you didn't even bother to rename the zip-file in which the OP of the last thread zipped his project, I think you didn't even bother to take his last version, in which some extra issues were solved.

if you really want to write an audio/wav/mp3/... player in java, my suggestion is: WRITE one in java. don't just show some code you don't know nothing about and can't explain anything about, so how are we going to have some help from your side? learn java. it's not like you need to know anything but core java to create an mp3 player in java, but you do have to understand something. if it's not core java, then at least the code you are working in, and as far as I've seen, you don't know neither of them. that's a bad place to start.

stultuske
Industrious Poster
4,366 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 23

Yeah you are totally right. I am taking an introductory to Software Development course and I haven't understood it as well as I wanted too.. Are you willing to help out? You are right. Instead of giving me the answers, I need pointers so I can figure things out for myself... Where do I start?

SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

by learning the basics. how far are you in your course, and what have you handled so far?
it's no use trying to code a media player if you don't understand/know the components you'll need.
it's like giving a toddler wood, hammer and nails, and expecting him to be able to build a desk. first learn what the nail is and does (your objects), check what your hammer (your calling class/method) is or the problems you can have with it and how to deal with it (exception handling).
these are just a few topics you'll need to understand before going over to larger projects.

stultuske
Industrious Poster
4,366 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 23
    I know how to write fields, contructors, methods(get and set), local variables,if/else statements, abstractions and modularization. Learning how to use a class name as a type for a variable right now. We are using a textbook called Objects First with Java using BlueJ written by Michael Kolling.. The thing is I  think I understand the material but when I have an assignment to do something I can't understand what it's asking me to do... 
SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

right now I am getting a high 75% in the course but I feel like I am not totally understand what I am doing... I know the more I practice the better I'll understand... I just can't understand what the question is asking me and how to go about it...

SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

we are more then half way finished the course and I don't have a good unerstanding of our material. I can pass the course but how do I move to the next course without understanding what I am being taught right now. i will definately fail.. I don't care about the grades. I just want to be confident with what I am being taught.

SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

I feel bad for trying to get answers from strangers and taking the easy way out... I don't want that. I want to learn. Do you have any suggestions?

SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

tell your teacher you still have questions and ask for more explanation.

Learning how to use a class name as a type for a variable right now.

that sentence allone tells me you 're not really familiar with what you're doing. you're not just using the classname, you are either instantiating a class or calling static members from class.

stultuske
Industrious Poster
4,366 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 23

How do I put (File soundFile) as the parameters in new Track()?

If Track has a constructor that accepts a File as a parameter, then just create a File and pass it, ie

File f = .... create the file as needed
track = new Track(f);

If Track does not have a constructor that accepts a File as a parameter, then you will have to create that constructor first...

public Track(File aFile) {
   ... do whatever the constructor needs to do
}
JamesCherrill
... trying to help
Moderator
8,497 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29

or look whether or not track has a set-method that accepts a File-parameter.

stultuske
Industrious Poster
4,366 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 23
public class Player
{
    private PlayList playList;
    private Track    track;



    /**
     * Constructor ...
     */
    public Player()
    {
        playList = new PlayList("audio");
    }

       /**
     * Return the track collection currently loaded in this player.
     */
    public PlayList getPlayList()
    {
        return playList;
    }

    /**
     * 
     */
    public void play()
    {
        if(track != null) {
           track.play();
        }    
    }

    public void stop()
    {
        if(track != null) {
           track.stop();  
        }
    }

    /**
     * 
     */
    public void setTrack(int trackNumber)
    {

    }

    /**
     * 
     */
    public String getTrackName()
    {
        return track.getName();
    }

    /**
     * Return information about the currently selected track. The information
     * contains the track name and playing time, in the format
     *    track-name (playing time)
     * Return an empty string if no track is selected.
     */
    public String getTrackInfo()
    {
        if(track != null) {
           System.out.println(track.getName() + "(" + track.getDuration() + ")");
        }
        return " ";
    }
}    

Do I create a int field to assign in the setTrack method? My code compiles but I can not play any songs in the GUI class. Can someone go over my work? Thank you.

SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

in a setTrack method, I would expect an instance of Track being passed as parameter, something like this:

public void setTrack(Track newTrack){
this.track = newTrack;
}
stultuske
Industrious Poster
4,366 posts since Jan 2007
Reputation Points: 1,318
Solved Threads: 610
Skill Endorsements: 23

but the parameter is an int . I can't change the method details. shouldn't I use a local variable?

SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Ok I completed the setTrack method.

 public void setTrack(int trackNumber)
    { 
        Track pTrack;
        if(track != null) {
            pTrack = track;
            pTrack.stop();
        }
        track = playList.getTrack(trackNumber); 
        track.rewind();
    }
SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
 I need help in this method, can someone help?

> /**
>      * Return information about the currently selected track. The information
>      * contains the track name and playing time, in the format
>      *    track-name (playing time)
>      * Return an empty string if no track is selected.
>      */
>     public String getTrackInfo()
      {

      }
SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
 return track.getName()+ "(" + track.getDuration() + ")";

I know that'll return the name and playing time but if no track is selected I need to have an empty string. So how do I write this?

SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

ok I solved that as well ..

SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

I need help with ...

Challenge tasks
Implement three more methods:
• one method named getNumberOfTracksPlayed that returns the number of tracks that
have been played (i.e. that have been started) since the player was started. The return
value should be an int.
• one method named getTotalPlayedTrackLength that returns the total playing time of all
tracks that have been played (or, to be more precise: started to play. We don’t care
whether they were played completely). The result is an int.
• one method named averageTrackLength that returns the average length of the tracks
played. The result is of type double.

public int getNumberOfTracksPlayed()
{
}

public int getTotalPlayedTrackLength()
{
}

public double averageTrackLength()
{
}
SuperManofBC
Light Poster
44 posts since May 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1250 seconds using 2.83MB