diff --git a/music/1.png b/music/1.png new file mode 100644 index 0000000..2d62beb Binary files /dev/null and b/music/1.png differ diff --git a/music/2.png b/music/2.png new file mode 100644 index 0000000..2de5623 Binary files /dev/null and b/music/2.png differ diff --git a/music/3.png b/music/3.png new file mode 100644 index 0000000..ea340a3 Binary files /dev/null and b/music/3.png differ diff --git a/music/README2.md b/music/README2.md new file mode 100644 index 0000000..0c20863 --- /dev/null +++ b/music/README2.md @@ -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. + + diff --git a/music/musicplayer.java b/music/musicplayer.java new file mode 100644 index 0000000..3a59cf7 --- /dev/null +++ b/music/musicplayer.java @@ -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(); + } +} \ No newline at end of file