Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Task_5/lib/jl1.0.1.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions Task_5/manifest.mf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

1,420 changes: 1,420 additions & 0 deletions Task_5/nbproject/build-impl.xml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Task_5/nbproject/genfiles.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build.xml.data.CRC32=652a6206
build.xml.script.CRC32=2cc291bd
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=652a6206
nbproject/build-impl.xml.script.CRC32=c46ee1f5
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
2 changes: 2 additions & 0 deletions Task_5/nbproject/private/private.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
compile.on.save=true
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.2\\build.properties
12 changes: 12 additions & 0 deletions Task_5/nbproject/private/private.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/F:/Task_5/Task_5/src/task_5/View.java</file>
<file>file:/F:/Task_5/Task_5/src/task_5/Driver.java</file>
<file>file:/F:/Task_5/Task_5/src/task_5/Application.java</file>
<file>file:/F:/Task_5/Task_5/src/task_5/Controller.java</file>
</group>
</open-files>
</project-private>
76 changes: 76 additions & 0 deletions Task_5/nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/Task_5.jar
dist.javadoc.dir=${dist.dir}/javadoc
excludes=
file.reference.jl1.0.1.jar=D:\\temp\\JLayer1.0.1\\jl1.0.1.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.jl1.0.1.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=task_5.Driver
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
15 changes: 15 additions & 0 deletions Task_5/nbproject/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>Task_5</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
92 changes: 92 additions & 0 deletions Task_5/src/task_5/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package task_5;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;

/**
*
* @author cleanrun
*/
public class Application {
private ArrayList<String> musicList;
private ThreadPlayer thread;
private int nowPlaying;


public Application(){
musicList = new ArrayList<>();
}

public void addMusic(String path){
musicList.add(path);
}

public String[] getMusicList(){
return (String[]) musicList.toArray(new String[0]);
}

public String getNowPlayed(){
return musicList.get(nowPlaying);
}

public void removeMusic(int i){
musicList.remove(i);
}

public void play(int i){
nowPlaying = i;
String filepath = musicList.get(i);
thread = new ThreadPlayer(filepath);
thread.start();
}

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

public void next(){
if(nowPlaying < musicList.size() - 1){
stop();
play(nowPlaying + 1);
}
}

public void prev(){
if(nowPlaying != 0){
stop();
play(nowPlaying - 1);
}
}

private class ThreadPlayer extends Thread{
private String filepath;
private Player player;

public ThreadPlayer(String filepath){
this.filepath = filepath;
}

@Override
public void run(){
try{
FileInputStream fis = new FileInputStream(filepath);
player = new Player(fis);
player.play();
}catch(FileNotFoundException e){
throw new IllegalStateException("File " + filepath + " not found");
}catch(JavaLayerException e){
throw new IllegalStateException("Error while playing file");
}
}
}
}
73 changes: 73 additions & 0 deletions Task_5/src/task_5/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package task_5;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
*
* @author cleanrun
*/
public class Controller implements ActionListener{
private Application model;
private View view;

public Controller(){
model = new Application();
view = new View();
view.setVisible(true);
view.addActionListener(this);
view.setListMusic(model.getMusicList());
}

@Override
public void actionPerformed(ActionEvent ae) {
Object click = ae.getSource();

try{
if(click.equals(view.getButtonAdd())){
JFileChooser fc = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("mp3 Files", "mp3", "mp3");
fc.setFileFilter(filter);
int returnVal = fc.showOpenDialog(view);

if(returnVal == JFileChooser.APPROVE_OPTION){
String path = fc.getSelectedFile().getAbsolutePath();
model.addMusic(path);
view.setListMusic(model.getMusicList());
}
}
else if(click.equals(view.getButtonDelete())){
int selected = view.getSelectedMusic();
model.removeMusic(selected);
view.setListMusic(model.getMusicList());
}
else if(click.equals(view.getButtonNext())){
model.next();
view.setFieldPlaying(model.getNowPlayed());
}
else if(click.equals(view.getButtonPlay())){
int selected = view.getSelectedMusic();
model.stop();
model.play(selected);
view.setFieldPlaying(model.getNowPlayed());
}
else if(click.equals(view.getButtonPrev())){
model.prev();
view.setFieldPlaying(model.getNowPlayed());
}
else if(click.equals(view.getButtonStop())){
model.stop();
view.setFieldPlaying("");
}
}catch(Exception e){
JOptionPane.showMessageDialog(view, e.getMessage());
}
}
}
21 changes: 21 additions & 0 deletions Task_5/src/task_5/Driver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package task_5;

/**
*
* @author cleanrun
*/
public class Driver {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Controller c = new Controller();
}

}
Loading