Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Please assist me to implement these mp3player methods

    The user needs to be able to:

    * Create playlists
    * Delete playlists
    * Edit playlists
    * play playlists
    The methos are in Mp3playerImpl and PlayListImpl


    com.xxx.iopackage.inputstreams.mp3player.playlist.PlayList
    com.xxx.iopackage.inputstreams.mp3playerMp3Player

    com.xxx.iopackage.inputstreams.mp3player.playlist.PlayListImpl
    com.xxx.iopackage.inputstreams.mp3playerMp3PlayerImpl


    mp3player

    package com.xxx.iopackage.inputstreams.mp3player;

    import java.io.File;
    import java.util.List;

    import com.xxx.iopackage.inputstreams.mp3player.playlist.PlayList;

    /**
    * Models a mp3 player
    *
    */
    public interface Mp3Player {

    /**
    * Plays an Mp3 file
    *
    * @param mp3File
    */
    public void play( File mp3File );


    /**
    * Adds a mp3 to the playlist
    *
    * @param playList
    * @param mp3File
    */
    public void addToPlayList( PlayList playList, File mp3File );

    /**
    * Creates a playlist
    *
    * @param playListName
    * @return
    */
    public PlayList createPlayList( String playListName );

    /**
    * Stores a playlist to the file system
    *
    * @param playList the playlist to store
    */
    public void storePlayList( PlayList playList );

    /**
    * Removes a playlist from the file system
    *
    * @param playList
    */
    public void removePlayList( PlayList playList );


    /**
    * Removes a playlist from the file system
    *
    * @param playListName
    */
    public void removePlayList( String playListName );


    /**
    * Returns all the playlists saved to the file system
    *
    * @return all playlists saved to the file system
    */
    public List<PlayList> getPlayLists();



    /**
    * Plays a playlist
    */
    public void playPlayList();


    /**
    * Shows the main menu
    */
    public void showMainMenu();

    /**
    * Shows an error to the console
    *
    * @param message error message to show to the console
    */
    public void showError( String message );
    }





    Mp3PlayerImpl.java

    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.util.List;

    import javazoom.jl.decoder.JavaLayerException;
    import javazoom.jl.player.Player;

    import org.apache.log4j.BasicConfigurator;
    import org.apache.log4j.Logger;

    import com.xxx.iopackage.inputstreams.mp3player.gui.AbstractCommandlineGui;
    import com.xxx.iopackage.inputstreams.mp3player.playlist.PlayList;

    public class Mp3PlayerImpl extends AbstractCommandlineGui
    implements Mp3Player {

    public static final Logger logger =
    Logger.getLogger( Mp3PlayerImpl.class );


    /**
    * Constructor
    */
    public Mp3PlayerImpl() {

    super();
    }


    /**
    * Shows the Play Mp3 Menu
    */
    private void showPlayMp3Menu() {

    boolean stay = true;

    while ( stay ) {
    StringBuffer sb = new StringBuffer( LINE_SEPARATOR );
    sb.append( LINE_SEPARATOR );
    sb.append( "Select MP3" );
    sb.append( LINE_SEPARATOR );
    sb.append( "==========" );
    sb.append( LINE_SEPARATOR );
    sb.append( "Please enter the path of a mp3 to play or x to exit" );

    System.out.println( sb.toString() );

    String pathToMp3 = readInput();

    if ( pathToMp3.equals( "x" ) ) {

    stay = false;
    break;
    }

    File mp3File = new File( pathToMp3 );
    sb = new StringBuffer();

    while ( stay ) {

    if ( ! mp3File.exists() ) {

    sb.append( LINE_SEPARATOR );

    sb.append(
    "Could not find mp3. Please enter a correct " +
    "path or x to exit" );

    System.out.println( sb.toString() );

    pathToMp3 = readInput();

    if ( pathToMp3.equals( "x" ) ) {
    stay = false;
    break;
    }
    }
    else {

    play( mp3File );

    break;
    }
    }
    }

    }


    public void addToPlayList( PlayList playList, File mp3File ) {

    // YOU NEED TO IMPLEMENT THIS METHOD
    }

    public PlayList createPlayList( String playListName ) {

    // YOU NEED TO IMPLEMENT THIS METHOD
    return null;
    }



    public List<PlayList> getPlayLists() {

    // YOU NEED TO IMPLEMENT THIS METHOD
    return null;
    }


    public void playPlayList() {

    // YOU NEED TO IMPLEMENT THIS METHOD
    }


    public void removePlayList( PlayList playList ) {

    // YOU NEED TO IMPLEMENT THIS METHOD
    }


    public void removePlayList( String playListName ) {

    // YOU NEED TO IMPLEMENT THIS METHOD
    }


    public void storePlayList( PlayList playList ) {

    // YOU NEED TO IMPLEMENT THIS METHOD
    }


    public void showMainMenu() {

    // YOU NEED TO IMPLEMENT THIS METHOD

    while ( true ) {

    StringBuffer sb = new StringBuffer( LINE_SEPARATOR );
    sb.append( LINE_SEPARATOR );
    sb.append( "Menu" );
    sb.append( LINE_SEPARATOR );
    sb.append( "====" );
    sb.append( LINE_SEPARATOR );
    sb.append( "1. Play Mp3" );
    sb.append( LINE_SEPARATOR );
    sb.append( "2. Exit" );
    sb.append( LINE_SEPARATOR );
    sb.append( LINE_SEPARATOR );
    sb.append( "Please enter a number for a menu option? " );

    System.out.println( sb.toString() );

    String menuOption = readInput();

    if ( menuOption.equals( "1" ) ) {

    showPlayMp3Menu();
    }
    else {

    break;
    }
    }
    }


    public void showError( String message ) {

    logger.error( message );
    }


    public void play( File mp3File ) {

    final String pathToMp3File = mp3File.getAbsolutePath();

    try {
    FileInputStream fileInputStream =
    new FileInputStream( mp3File );

    BufferedInputStream bufferedInputStream =
    new BufferedInputStream( fileInputStream );

    Player player = new Player( bufferedInputStream );

    player.play();
    }
    catch( FileNotFoundException e ) {

    showError( "Could not find mp3 to play : " + pathToMp3File );
    }
    catch( JavaLayerException e ) {

    showError( "Problem initializing player with mp3 file, " +
    pathToMp3File );
    }

    }


    /**
    * Entry point to this application.
    *
    * @param args path to mp3
    */
    public static void main( String[] args ) {

    BasicConfigurator.configure();

    Mp3Player mp3Player = new Mp3PlayerImpl();

    String pathToMp3;

    if (args.length > 0 ) {

    pathToMp3 = args[ 0 ];
    mp3Player.play( new File( pathToMp3 ) );
    }
    else {

    mp3Player.showMainMenu();

    System.out.println( "Goodbye!" );
    }
    }
    }




    PlayList.java


    package com.xxx.iopackage.inputstreams.mp3player.playlist;

    import java.io.File;
    import java.util.LinkedHashSet;


    /**
    * Models a playlist of MP3. A Playlist is a group of mp3s which are played
    * one after another.
    */
    public interface PlayList {

    /**
    * Adds a mp3 to the playlist
    *
    * @param mp3
    */
    public void addMp3( File mp3 );


    /**
    * Gets the Mp3 as a LinkedHashSet. A LinkedHashSet returns the elements
    * in the order they were added to the LinkedHashSet
    *
    * @return list of Mp3 for this playlist
    */
    public LinkedHashSet<File> getMp3PlayList();


    /**
    * Removes a mp3 from the playlist
    *
    * @param mp3 the mp3 to remove from the playlist
    */
    public void removeFromPlayList( File mp3 );


    /**
    * Removes all mp3 from the playlist
    */
    public void removeAllMp3FromPlaylist();


    /**
    * Sets the name of the mp3 playlist
    *
    * @param playListName the name of the playlist
    */
    public void setName( String playListName );


    /**
    * Gets the name of the mp3 playlist
    *
    * @return the name of the mp3 playlist
    */
    public String getPlayListName();
    }






    PlayListImpl.java


    package com.xxx.iopackage.inputstreams.mp3player.playlist;

    import java.io.File;
    import java.util.LinkedHashSet;

    /**
    * Class modelling a playlist of Mp3 tunes
    *
    */
    public class PlayListImpl implements PlayList {

    /**
    * Constructor
    */
    public PlayListImpl() {

    super();
    }

    /* (non-Javadoc)
    * @see com.xxx.iopackage.inputstreams.mp3player.playlist.
    * PlayList#addMp3(java.io.File)
    */
    public void addMp3( File mp3 ) {

    // YOU NEED TO IMPLEMENT THIS METHOD
    }


    /* (non-Javadoc)
    * @see com.xxx.iopackage.inputstreams.mp3player.playlist.
    * PlayList#getMp3PlayList()
    */
    public LinkedHashSet<File> getMp3PlayList() {

    // YOU NEED TO IMPLEMENT THIS METHOD
    return null;
    }


    /* (non-Javadoc)
    * @see com.xxx.iopackage.inputstreams.mp3player.playlist.
    * PlayList#getPlayListName()
    */
    public String getPlayListName() {

    // YOU NEED TO IMPLEMENT THIS METHOD
    return null;
    }


    /* (non-Javadoc)
    * @see com.xxx.iopackage.inputstreams.mp3player.playlist.
    * PlayList#removeAllMp3FromPlaylist()
    */
    public void removeAllMp3FromPlaylist() {

    // YOU NEED TO IMPLEMENT THIS METHOD
    }


    /* (non-Javadoc)
    * @see com.xxx.iopackage.inputstreams.mp3player.playlist.
    * PlayList#removeFromPlayList(java.io.File)
    */
    public void removeFromPlayList( File mp3 ) {

    // YOU NEED TO IMPLEMENT THIS METHOD
    }


    /* (non-Javadoc)
    * @see com.xxx.iopackage.inputstreams.mp3player.playlist.
    * PlayList#setName(java.lang.String)
    */
    public void setName( String playListName ) {

    // YOU NEED TO IMPLEMENT THIS METHOD
    }
    }

  • #2
    Regular Coder
    Join Date
    Jan 2009
    Location
    india
    Posts
    145
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Follow Posting guidelines when asking questions, don't post entire code here and expect some one to implement methods for you. Be specific. you should ask, 'I am getting blah blah problem when ' implementing a method, how to solve it.' And you will get more responses


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •