Guides:  Drivers | Questions & Answers | Software | Write to Us
Technical Questions and Answers Silicon Guide
Search SiliconGuide:

Programming Issues

Questions & Answers > Programming
Irene on January 31, 2012
Programming Issues

Hi!
I have been trying to finish this program and now am stuck. Could someone please help me out at the commented areas //You need to implement this method.

Q: Mp3Player

package com.jjpeople.iopackage.readerwriter.mp3player;

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.jjpeople.iopackage.readerwriter.mp3player.gui.AbstractCommandlineGui;
import com.jjpeople.iopackage.readerwriter.mp3player.playlist.PlayList;

/**
* Class that plays MP3
*
*
*/
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;
}
}
}

}


/* (non-Javadoc)
* @see com.jjpeople.iopackage.inputstreams.mp3player.
* Mp3Player#addToPlayList(
* com.jjpeople.iopackage.inputstreams.mp3player.PlayList,
* java.io.File)
*/
public void addToPlayList( PlayList playList, File mp3File ) {

// YOU NEED TO IMPLEMENT THIS METHOD
}


/* (non-Javadoc)
* @see com.jjpeople.iopackage.inputstreams.mp3player.
* Mp3Player#createPlayList(java.lang.String)
*/
public PlayList createPlayList( String playListName ) {

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


/* (non-Javadoc)
* @see com.jjpeople.iopackage.inputstreams.mp3player.
* Mp3Player#getPlayLists()
*/
public List getPlayLists() {

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


/* (non-Javadoc)
* @see com.jjpeople.iopackage.inputstreams.mp3player.
* Mp3Player#playPlayList()
*/
public void playPlayList() {

// YOU NEED TO IMPLEMENT THIS METHOD
}


/* (non-Javadoc)
* @see com.jjpeople.iopackage.inputstreams.mp3player.
* Mp3Player#removePlayList(com.jjpeople.iopackage.inputstreams.
* mp3player.PlayList)
*/
public void removePlayList( PlayList playList ) {

// YOU NEED TO IMPLEMENT THIS METHOD
}


/* (non-Javadoc)
* @see com.jjpeople.iopackage.inputstreams.mp3player.
* Mp3Player#removePlayList(java.lang.String)
*/
public void removePlayList( String playListName ) {

// YOU NEED TO IMPLEMENT THIS METHOD
}


/* (non-Javadoc)
* @see com.jjpeople.iopackage.inputstreams.mp3player.
* Mp3Player#storePlayList(
* com.jjpeople.iopackage.inputstreams.mp3player.PlayList)
*/
public void storePlayList( PlayList playList ) {

// YOU NEED TO IMPLEMENT THIS METHOD
}


/* (non-Javadoc)
* @see com.jjpeople.iopackage.inputstreams.mp3player.Mp3Player#showMenu()
*/
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;
}
}
}


/* (non-Javadoc)
* @see com.jjpeople.iopackage.inputstreams.mp3player.Mp3Player#showError(
* java.lang.String)
*/
public void showError( String message ) {

logger.error( message );
}


/* (non-Javadoc)
* @see com.jjpeople.iopackage.inputstreams.mp3player.
* Mp3Player#play(java.io.File)
*/
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!" );
}
}
}

c)language tutor
Provide an Answer
Name
Answer

Reload Image

Enter the code displayed above here:
 

Didn't find what you were looking for on this page?
Browse all Programming related questions
Browse all Questions and Answers
Copyright 1999 - 2016 SiliconPharm Corporation, All Rights Reserved