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 music/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added music/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added music/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions music/README2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# MUSIC PLAYER

## Introduction
The application should offer users a comprehensive and intuitive interface for managing and enjoying their music, incorporating innovative features to enhance the listening experience.

## Usage
Upon launching the application, users are presented with a user-friendly interface that displays thumbnails or a list of available image files.
The UI may include navigation controls such as buttons, PLAY, PAUSE, RESUME, LOOP.

## Example
![home](1.png)
![home](2.png)
![home](3.png)

## Dependencies
1. JAVA
2. AWAIT

## How it Works
1. Users can select a song from their library to play by browsing through their music collection or searching for specific tracks.
Once a song is selected, the application initiates playback, and the audio is streamed or played directly from the device's storage.
2. The application provides standard playback controls such as play, pause, stop, loop.


## Contribution
Contributions are welcome! Feel free to submit issues or pull requests.


167 changes: 167 additions & 0 deletions music/musicplayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.sound.sampled.*;
import javax.swing.*;
import javax.swing.filechooser.*;

public class musicplayer extends JFrame implements ActionListener {

/**
*
*/
private static final long serialVersionUID = 1L;
private JTextField filePathField;
private JButton playButton;
private JButton pauseButton;
private JButton chooseButton;
private JButton loopButton;
private boolean isPaused;
private boolean isLooping = false;
private JFileChooser fileChooser;
private Clip clip;

public musicplayer()
{
super("Music Player");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());

filePathField = new JTextField(20);
playButton = new JButton("Play");
pauseButton = new JButton("Pause");
chooseButton = new JButton("Choose File");
loopButton = new JButton("Loop");
isPaused = false;
isLooping = false;

playButton.addActionListener(this);
pauseButton.addActionListener(this);
chooseButton.addActionListener(this);
loopButton.addActionListener(this);

add(filePathField);
add(chooseButton);
add(playButton);
add(pauseButton);
add(loopButton);

fileChooser = new JFileChooser(".");
fileChooser.setFileFilter(new FileNameExtensionFilter("WAV Files", "wav"));

setSize(500, 100);
setLocationRelativeTo(null);
setVisible(true);
}

@Override
public void actionPerformed(ActionEvent event) {

if (event.getSource() == playButton)
{
playMusic();
}
else if (event.getSource() == pauseButton)
{
pauseMusic();
}
else if (event.getSource() == chooseButton)
{
chooseFile();
}
else if (event.getSource() == loopButton)
{
toggleLoop();
}
}

private void playMusic() {

if (clip != null && clip.isRunning())
{
clip.stop();
}

try
{
File file = new File(filePathField.getText());
AudioInputStream audioIn = AudioSystem.getAudioInputStream(file);

clip = AudioSystem.getClip();
clip.open(audioIn);

if (isLooping)
{
clip.loop(Clip.LOOP_CONTINUOUSLY);
}

clip.start();

}
catch(Exception e)
{
System.out.println(e);
}

}

private void pauseMusic()
{
if (clip != null && clip.isRunning())
{
clip.stop();
isPaused = true;
pauseButton.setText("Resume");
}
else if (clip != null && isPaused)
{
clip.start();

if(isLooping)
{
clip.loop(Clip.LOOP_CONTINUOUSLY);
}

isPaused = false;
pauseButton.setText("Pause");
}
}

private void chooseFile()
{
fileChooser.setCurrentDirectory(new File("."));
int result = fileChooser.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION)
{
File selectedFile = fileChooser.getSelectedFile();
filePathField.setText(selectedFile.getAbsolutePath());
}
}

private void toggleLoop()
{
isLooping = !isLooping;
if (isLooping)
{
loopButton.setText("Stop Loop");

if(clip.isRunning())
{
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
}
else
{
loopButton.setText("Loop");

if(clip.isRunning())
{
clip.loop(0);
}
}
}

public static void main(String[] args) {
new musicplayer();
}
}