diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3145967..0091cd3 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,34 +7,35 @@ - - + + - - - - - - - - - - + + + + + + + + + + + + - + - - - - + + + - + - - + + - - - - + + - - + + - - + - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + + + + + + + + + + + + @@ -102,26 +139,26 @@ - - + + - - + + - - + + - + - - + + @@ -129,6 +166,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -140,12 +208,6 @@ - System - trackSpeaker = current.getTrackLine(); - current = - open - atta - jvm pause( seek( getDUra @@ -170,6 +232,11 @@ int get goto stopT + gettrackL + open + total + addM + for @@ -178,14 +245,6 @@ @@ -239,10 +306,10 @@ - @@ -277,6 +344,14 @@ + + + + + + + + @@ -290,7 +365,15 @@ - + + + + + + + + + @@ -320,14 +403,19 @@ - - + + + + + + + @@ -335,10 +423,6 @@ - - - - - + - - @@ -483,11 +564,11 @@ - + - + @@ -495,7 +576,7 @@ - + @@ -503,11 +584,11 @@ + - @@ -518,14 +599,14 @@ - + + - @@ -535,7 +616,7 @@ - + @@ -556,347 +637,398 @@ - + + + + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - + - + - - + + - + - - + + - + - - + + - + - - + + - + + - - + + + + + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - - - - - - + - - + + - - - - - + - - + + - + - - + + - + - - + + - + - - - - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + + - - + + - + - - + + - + - - + + - + - - + + - - + - - + + + + + + - + - - + + - + - - + + - - + - + - - + + - + - - + + - + - - + + - + - - + + + + + - + - - + + + + + + - + - - + + + + + - + - - + + - + - - + + - + - - + + - + - - + + - - - + + - + - - + + + + + + + + + + + + + + + + + - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OrangePlayer.iml b/OrangePlayer.iml index 7c4081e..659c41c 100644 --- a/OrangePlayer.iml +++ b/OrangePlayer.iml @@ -58,5 +58,23 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 6693114..3cdac0a 100644 --- a/README.md +++ b/README.md @@ -66,3 +66,9 @@ Music player library in pure Java. abstracto de la clase padre Track ## Se añade opcion de ver tiempo actual de la cancion ## Se añade opcion de dirigirse a un segundo especifico de la cancion (No disponible correctamente en archivos FLAC y M4A) +# 0.6.1 Beta + ## Se añade funcion para agregar más musica al reproductor + +## 0.7 + ## Se logra obtener duracion de archivos de audio para todos los formatos disponibles + ## Se añade opcion para obtener la caratula de un archivo de audio cualquiera diff --git a/bin/OrangePlayer.jar b/bin/OrangePlayer.jar index 48cdf0b..21db588 100644 Binary files a/bin/OrangePlayer.jar and b/bin/OrangePlayer.jar differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/AudioInfo.class b/out/production/OrangePlayer/org/orangeplayer/audio/AudioInfo.class new file mode 100644 index 0000000..5625302 Binary files /dev/null and b/out/production/OrangePlayer/org/orangeplayer/audio/AudioInfo.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/Player.class b/out/production/OrangePlayer/org/orangeplayer/audio/Player.class index 878b08e..e71221e 100644 Binary files a/out/production/OrangePlayer/org/orangeplayer/audio/Player.class and b/out/production/OrangePlayer/org/orangeplayer/audio/Player.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/Player2.class b/out/production/OrangePlayer/org/orangeplayer/audio/Player2.class deleted file mode 100644 index 3713c48..0000000 Binary files a/out/production/OrangePlayer/org/orangeplayer/audio/Player2.class and /dev/null differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/Track.class b/out/production/OrangePlayer/org/orangeplayer/audio/Track.class index 6dc5be7..e897159 100644 Binary files a/out/production/OrangePlayer/org/orangeplayer/audio/Track.class and b/out/production/OrangePlayer/org/orangeplayer/audio/Track.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/codec/FlacDecoder.class b/out/production/OrangePlayer/org/orangeplayer/audio/codec/FlacDecoder.class index 00b92a5..372db9c 100644 Binary files a/out/production/OrangePlayer/org/orangeplayer/audio/codec/FlacDecoder.class and b/out/production/OrangePlayer/org/orangeplayer/audio/codec/FlacDecoder.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/formats/FlacTrack.class b/out/production/OrangePlayer/org/orangeplayer/audio/formats/FlacTrack.class index bd291a7..90e0884 100644 Binary files a/out/production/OrangePlayer/org/orangeplayer/audio/formats/FlacTrack.class and b/out/production/OrangePlayer/org/orangeplayer/audio/formats/FlacTrack.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/formats/M4ATrack.class b/out/production/OrangePlayer/org/orangeplayer/audio/formats/M4ATrack.class new file mode 100644 index 0000000..2f8fb8d Binary files /dev/null and b/out/production/OrangePlayer/org/orangeplayer/audio/formats/M4ATrack.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/formats/MP3Track.class b/out/production/OrangePlayer/org/orangeplayer/audio/formats/MP3Track.class index 42af10b..ae75621 100644 Binary files a/out/production/OrangePlayer/org/orangeplayer/audio/formats/MP3Track.class and b/out/production/OrangePlayer/org/orangeplayer/audio/formats/MP3Track.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/formats/MP4Track.class b/out/production/OrangePlayer/org/orangeplayer/audio/formats/MP4Track.class deleted file mode 100644 index 9fc8b62..0000000 Binary files a/out/production/OrangePlayer/org/orangeplayer/audio/formats/MP4Track.class and /dev/null differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/formats/OGGTrack.class b/out/production/OrangePlayer/org/orangeplayer/audio/formats/OGGTrack.class index e625c00..acba583 100644 Binary files a/out/production/OrangePlayer/org/orangeplayer/audio/formats/OGGTrack.class and b/out/production/OrangePlayer/org/orangeplayer/audio/formats/OGGTrack.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/formats/PCMTrack.class b/out/production/OrangePlayer/org/orangeplayer/audio/formats/PCMTrack.class index 5d78158..b0ed653 100644 Binary files a/out/production/OrangePlayer/org/orangeplayer/audio/formats/PCMTrack.class and b/out/production/OrangePlayer/org/orangeplayer/audio/formats/PCMTrack.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/audio/interfaces/PlayerControls.class b/out/production/OrangePlayer/org/orangeplayer/audio/interfaces/PlayerControls.class index c2ceb63..bdc9ba5 100644 Binary files a/out/production/OrangePlayer/org/orangeplayer/audio/interfaces/PlayerControls.class and b/out/production/OrangePlayer/org/orangeplayer/audio/interfaces/PlayerControls.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/main2/TestAAC2.class b/out/production/OrangePlayer/org/orangeplayer/main2/TestAAC2.class deleted file mode 100644 index 78d69f1..0000000 Binary files a/out/production/OrangePlayer/org/orangeplayer/main2/TestAAC2.class and /dev/null differ diff --git a/out/production/OrangePlayer/org/orangeplayer/main2/TestPlayer.class b/out/production/OrangePlayer/org/orangeplayer/main2/TestPlayer.class deleted file mode 100644 index e6db07f..0000000 Binary files a/out/production/OrangePlayer/org/orangeplayer/main2/TestPlayer.class and /dev/null differ diff --git a/out/production/OrangePlayer/org/orangeplayer/ontesting/AudioTaggerTest.class b/out/production/OrangePlayer/org/orangeplayer/ontesting/AudioTaggerTest.class new file mode 100644 index 0000000..78c0ca5 Binary files /dev/null and b/out/production/OrangePlayer/org/orangeplayer/ontesting/AudioTaggerTest.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/ontesting/TestAAC2.class b/out/production/OrangePlayer/org/orangeplayer/ontesting/TestAAC2.class new file mode 100644 index 0000000..4aee5a7 Binary files /dev/null and b/out/production/OrangePlayer/org/orangeplayer/ontesting/TestAAC2.class differ diff --git a/out/production/OrangePlayer/org/orangeplayer/ontesting/TestPlayer.class b/out/production/OrangePlayer/org/orangeplayer/ontesting/TestPlayer.class new file mode 100644 index 0000000..d296350 Binary files /dev/null and b/out/production/OrangePlayer/org/orangeplayer/ontesting/TestPlayer.class differ diff --git a/src/org/orangeplayer/audio/AudioInfo.java b/src/org/orangeplayer/audio/AudioInfo.java new file mode 100644 index 0000000..ac59d90 --- /dev/null +++ b/src/org/orangeplayer/audio/AudioInfo.java @@ -0,0 +1,46 @@ +package org.orangeplayer.audio; + +import org.jaudiotagger.audio.AudioFile; +import org.jaudiotagger.audio.AudioFileIO; +import org.jaudiotagger.audio.AudioHeader; +import org.jaudiotagger.audio.exceptions.CannotReadException; +import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException; +import org.jaudiotagger.audio.exceptions.ReadOnlyFileException; +import org.jaudiotagger.tag.FieldKey; +import org.jaudiotagger.tag.Tag; +import org.jaudiotagger.tag.TagException; +import org.jaudiotagger.tag.images.Artwork; + +import java.io.File; +import java.io.IOException; + +public class AudioInfo { + private AudioFile audioFile; + private Tag fileTag; + private AudioHeader header; + + public AudioInfo(File sound) + throws TagException, ReadOnlyFileException, + CannotReadException, InvalidAudioFrameException, IOException { + this.audioFile = AudioFileIO.read(sound); + fileTag = audioFile.getTag(); + header = audioFile.getAudioHeader(); + } + + public String getTag(FieldKey tag) { + return fileTag.getFirst(tag); + } + + public String getTag(String tagName) { + return getTag(FieldKey.valueOf(tagName.toUpperCase())); + } + + public int getDuration() { + return header.getTrackLength(); + } + + public Artwork getCover() { + return fileTag.getFirstArtwork(); + } + +} diff --git a/src/org/orangeplayer/audio/Player.java b/src/org/orangeplayer/audio/Player.java index a9f7113..d295b9b 100644 --- a/src/org/orangeplayer/audio/Player.java +++ b/src/org/orangeplayer/audio/Player.java @@ -9,6 +9,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; public class Player extends Thread implements PlayerControls { @@ -43,7 +44,16 @@ public static Player getPlayer() { return player; }*/ - private Player(File rootFolder) throws FileNotFoundException { + public Player() { + this.rootFolder = rootFolder; + listSoundPaths = new ArrayList<>(); + listListeners = new ArrayList<>(); + trackIndex = 0; + currentVolume = DEFAULT_VOLUME; + on = false; + setName("ThreadPlayer "+getId()); + } + public Player(File rootFolder) throws FileNotFoundException { this.rootFolder = rootFolder; listSoundPaths = new ArrayList<>(); listListeners = new ArrayList<>(); @@ -71,7 +81,7 @@ public Player(String folderPath) throws FileNotFoundException { private void loadTracks(File folder) { File[] fldFiles = folder.listFiles(); - File f; + File f = null; if (fldFiles != null) for (int i = 0; i < fldFiles.length; i++) { f = fldFiles[i]; @@ -83,12 +93,11 @@ private void loadTracks(File folder) { } private void loadTracks(List listFiles) { - listSoundPaths.clear(); trackIndex = 0; - - // Se supone que todos son archivos - listFiles.stream().forEach((f)->{ - if (!f.isDirectory()) + listFiles.stream().forEach(f->{ + if (f.isDirectory()) + loadTracks(f); + else listSoundPaths.add(f.getPath()); }); } @@ -213,7 +222,12 @@ private void changeTrack() { current.finish(); } + private void waitForSongs() { + while (on && getSongsCount() == 0); + } + void loadNextTrack() { + waitForSongs(); Track cur = current; current = getNextTrack(); finishTrack(cur); @@ -223,15 +237,12 @@ void loadNextTrack() { System.out.println(current.getInfoSong()); } - - // Test public void jumpTrack(int jumps) { if (jumps > 0) trackIndex+=(--jumps); - else { + else trackIndex-=jumps; - } if (trackIndex >= listSoundPaths.size()) trackIndex = 0; else if (trackIndex < 0) @@ -297,12 +308,24 @@ public boolean isFinished() { return current == null ? false : current.isFinished(); } + @Override public void open(File sound) { - + listSoundPaths.clear(); + listSoundPaths.add(sound.getPath()); + if (isPlaying()) + playNext(); + else if (isAlive()) + play(); + else + start(); } + @Override public void open(List listSounds) { + listSounds.clear(); loadTracks(listSounds); + sortTracks(); + /* // Ver si el thread no es nulo if (current != null && currentThread.isAlive()) { current.kill(); @@ -310,12 +333,46 @@ public void open(List listSounds) { currentThread = new Thread(current); currentThread.start(); } + */ } - public int getCurrentProgress() { + @Override + public void addMusic(List listSounds) { + if (!listSounds.isEmpty()) { + if (listSounds instanceof LinkedList) { + listSounds.stream().forEach(sound->{ + if (sound.isDirectory()) + loadTracks(sound); + else + listSoundPaths.add(sound.getPath()); + }); + } + else { + File sound = null; + for (int i = 0; i < listSounds.size(); i++) { + sound = listSounds.get(i); + if (sound.isDirectory()) + loadTracks(sound); + else + listSoundPaths.add(sound.getPath()); + } + } + } + sortTracks(); } + + @Override + public void addMusic(File musicFolder) { + loadTracks(musicFolder); + sortTracks(); + } + + public int getTrackProgress() { return current.getProgress(); } + public int getSongsCount() { + return listSoundPaths.size(); + } @Override public void play() { if (!isAlive()) @@ -411,8 +468,6 @@ public void shutdown() { loadListenerMethod("onShutdown", null); } - - @Override public void run() { PlayerHandler.setInstance(this); diff --git a/src/org/orangeplayer/audio/Player2.java b/src/org/orangeplayer/audio/Player2.java deleted file mode 100644 index 0dba8f7..0000000 --- a/src/org/orangeplayer/audio/Player2.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.orangeplayer.audio; - -import org.orangeplayer.audio.interfaces.PlayerControls; - -import java.io.File; -import java.util.List; - -public class Player2 implements PlayerControls { - @Override - public void open(File sound) { - - } - - @Override - public void open(List listSounds) { - - } - - @Override - public void playNext() { - - } - - @Override - public void playPrevious() { - - } - - @Override - public void shutdown() { - - } - - @Override - public boolean isPlaying() throws Exception { - return false; - } - - @Override - public boolean isPaused() throws Exception { - return false; - } - - @Override - public boolean isStoped() throws Exception { - return false; - } - - @Override - public boolean isFinished() throws Exception { - return false; - } - - @Override - public void play() throws Exception { - - } - - @Override - public void pause() throws Exception { - - } - - @Override - public void resumeTrack() throws Exception { - - } - - @Override - public void stopTrack() throws Exception { - - } - - @Override - public void finish() throws Exception { - - } - - @Override - public void setGain(float volume) throws Exception { - - } - - @Override - public void seek(int bytes) throws Exception { - - } -} diff --git a/src/org/orangeplayer/audio/Track.java b/src/org/orangeplayer/audio/Track.java index 4f2966d..59ca692 100644 --- a/src/org/orangeplayer/audio/Track.java +++ b/src/org/orangeplayer/audio/Track.java @@ -1,6 +1,11 @@ package org.orangeplayer.audio; import org.aucom.sound.Speaker; +import org.jaudiotagger.audio.exceptions.CannotReadException; +import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException; +import org.jaudiotagger.audio.exceptions.ReadOnlyFileException; +import org.jaudiotagger.tag.FieldKey; +import org.jaudiotagger.tag.TagException; import org.orangeplayer.audio.codec.DecodeManager; import org.orangeplayer.audio.formats.*; import org.orangeplayer.audio.interfaces.MusicControls; @@ -11,7 +16,6 @@ import javax.sound.sampled.spi.AudioFileReader; import java.io.File; import java.io.IOException; -import java.util.Map; import static org.orangeplayer.audio.AudioExtensions.*; import static org.orangeplayer.audio.TrackStates.*; @@ -21,6 +25,7 @@ public abstract class Track implements Runnable, MusicControls { protected Speaker trackLine; protected AudioInputStream speakerAis; protected AudioFileReader audioReader; + protected AudioInfo info; protected byte state; protected int currentSeconds; @@ -50,7 +55,7 @@ else if (trackName.endsWith(WAVE) || trackName.endsWith(AU) result = new PCMTrack(fSound); else if (trackName.endsWith(M4A)){ System.out.println("Es mp4"); - result = new MP4Track(fSound); + result = new M4ATrack(fSound); } // Por si no tiene formato en el nombre else { @@ -94,13 +99,20 @@ public static Track getTrack(String trackPath) { return getTrack(new File(trackPath)); } - protected Track(File ftrack) throws LineUnavailableException, IOException, UnsupportedAudioFileException { + protected Track(File ftrack) + throws LineUnavailableException, IOException, UnsupportedAudioFileException { System.out.println("File: "+ftrack.getPath()); this.ftrack = ftrack; //stateCode = STOPED; state = STOPED; initLine(); currentSeconds = 0; + try { + info = new AudioInfo(ftrack); + } catch (TagException | ReadOnlyFileException | InvalidAudioFrameException | CannotReadException e) { + // For testing se imprime + e.printStackTrace(); + } } protected Track(String trackPath) throws LineUnavailableException, IOException, UnsupportedAudioFileException { @@ -123,7 +135,6 @@ public Speaker getTrackLine() { return trackLine; } - public File getTrackFile() { return ftrack; } @@ -181,25 +192,6 @@ protected void closeLine() { } } - protected String getProperty(String key) { - Map formatProper = null; - try { - AudioFileFormat fileFormat = getFileFormat(); - if (fileFormat != null) { - formatProper = getFileFormat().properties(); - if (formatProper != null) { - Object get = formatProper.get(key); - return get == null ? null : get.toString(); - } - else - return null; - } - } catch (IOException | UnsupportedAudioFileException e) { - e.printStackTrace(); - } - return null; - } - protected void closeAll() { closeLine(); currentSeconds = 0; @@ -297,33 +289,68 @@ public AudioFileFormat getFileFormat() throws IOException, UnsupportedAudioFileE return audioReader == null ? null : audioReader.getAudioFileFormat(ftrack); } - // Info + protected String getProperty(String key) { + /*Map formatProper = null; + try { + AudioFileFormat fileFormat = getFileFormat(); + if (fileFormat != null) { + formatProper = getFileFormat().properties(); + if (formatProper != null) { + Object get = formatProper.get(key); + return get == null ? null : get.toString(); + } + else + return null; + } + } catch (IOException | UnsupportedAudioFileException e) { + e.printStackTrace(); + }*/ + return info == null ? null : info.getTag(key); + } + + protected String getProperty(FieldKey key) { + if (info == null) + return null; + String tag = info.getTag(key).trim(); + return tag.isEmpty() ? null : tag; + } public String getTitle() { - String proper = getProperty("title"); - return proper == null ? ftrack.getName() : proper; + return getProperty(FieldKey.TITLE); } public String getAlbum() { - return getProperty("album"); + return getProperty(FieldKey.ALBUM); } public String getArtist() { - String author = getProperty("author"); - return author == null ? getProperty("artist") : author; + //return author == null ? getProperty("artist") : author; + return getProperty(FieldKey.ARTIST); } public String getDate() { - return getProperty("date"); + return getProperty(FieldKey.YEAR); + } + + public boolean hasCover() { + return info.getCover() != null; + } + + public byte[] getCoverData() { + return info.getCover().getBinaryData(); } public synchronized int getProgress() { return currentSeconds; } - public abstract long getDuration(); + public long getDuration() { + return info.getDuration(); + } - public abstract String getDurationAsString(); + public String getDurationAsString() { + return String.valueOf(getDuration()); + } // Testing public String getInfoSong() { diff --git a/src/org/orangeplayer/audio/codec/FlacDecoder.java b/src/org/orangeplayer/audio/codec/FlacDecoder.java index 141fafc..3b9d47d 100644 --- a/src/org/orangeplayer/audio/codec/FlacDecoder.java +++ b/src/org/orangeplayer/audio/codec/FlacDecoder.java @@ -16,6 +16,7 @@ * Decode FLAC file to WAV file application. * @author kc7bfi */ +@Deprecated public class FlacDecoder implements PCMProcessor { private WavWriter wav; private AudioInputStream decodedAis; diff --git a/src/org/orangeplayer/audio/formats/FlacTrack.java b/src/org/orangeplayer/audio/formats/FlacTrack.java index fa261a8..4cc6cd6 100644 --- a/src/org/orangeplayer/audio/formats/FlacTrack.java +++ b/src/org/orangeplayer/audio/formats/FlacTrack.java @@ -52,6 +52,7 @@ protected void loadAudioStream() { speakerAis = new FlacFormatConversionProvider(). getAudioInputStream(decodedFormat, flacAis); + } catch (UnsupportedAudioFileException | IOException e) { e.printStackTrace(); } @@ -64,22 +65,11 @@ protected short getSecondsByBytes(int readedBytes) { return (short) ((readedBytes * secs) / fLen); } - @Override + /*@Override public long getDuration() { - AudioFormat format = speakerAis.getFormat(); - // Bits por sample, channels y sampleRate - System.out.println(format.getSampleSizeInBits()); - double bcm = format.getSampleSizeInBits() - *format.getChannels()*format.getSampleRate(); - long fLen = ftrack.length(); - - System.out.println(format.getSampleRate()); - System.out.println(format.getFrameRate()); - System.out.println(format.getFrameSize()); - System.out.println(format.getSampleSizeInBits()); - System.out.println("BCM: "+bcm); - System.out.println("FLen: "+fLen); - return (long) (fLen / bcm); + long frames = speakerAis.getFrameLength(); + return (long) ((float)frames / + speakerAis.getFormat().getFrameRate()); } @Override @@ -89,7 +79,7 @@ public String getDurationAsString() { sec = sec-(min*60); return new StringBuilder().append(min) .append(':').append(sec < 10 ? '0'+sec:sec).toString(); - } + }*/ @Override public void seek(int seconds) { @@ -107,9 +97,9 @@ public void seek(int seconds) { public static void main(String[] args) { FlacTrack track = (FlacTrack) Track.getTrack( - "/home/martin/AudioTesting/audio/flac2.flac"); + "/home/martin/AudioTesting/audio/flac.flac"); new Thread(track).start(); - track.setGain(80); + track.setGain(0); System.out.println(track.getInfoSong()); } diff --git a/src/org/orangeplayer/audio/formats/MP4Track.java b/src/org/orangeplayer/audio/formats/M4ATrack.java similarity index 85% rename from src/org/orangeplayer/audio/formats/MP4Track.java rename to src/org/orangeplayer/audio/formats/M4ATrack.java index 764ae60..4b5b2b4 100644 --- a/src/org/orangeplayer/audio/formats/MP4Track.java +++ b/src/org/orangeplayer/audio/formats/M4ATrack.java @@ -3,11 +3,9 @@ import net.sourceforge.jaad.aac.Decoder; import net.sourceforge.jaad.aac.SampleBuffer; import net.sourceforge.jaad.mp4.MP4Container; -import net.sourceforge.jaad.mp4.MP4InputStream; import net.sourceforge.jaad.mp4.api.AudioTrack; import net.sourceforge.jaad.mp4.api.Frame; import net.sourceforge.jaad.mp4.api.Movie; -import net.sourceforge.jaad.mp4.boxes.impl.meta.ID3TagBox; import net.sourceforge.jaad.spi.javasound.AACAudioFileReader; import org.orangeplayer.audio.Track; @@ -16,17 +14,15 @@ import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; import java.io.*; -import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; import java.util.List; -public class MP4Track extends Track { - public MP4Track(File ftrack) throws LineUnavailableException, IOException, UnsupportedAudioFileException { +public class M4ATrack extends Track { + public M4ATrack(File ftrack) throws LineUnavailableException, IOException, UnsupportedAudioFileException { super(ftrack); } - public MP4Track(String trackPath) throws LineUnavailableException, IOException, UnsupportedAudioFileException { + public M4ATrack(String trackPath) throws LineUnavailableException, IOException, UnsupportedAudioFileException { super(trackPath); } @@ -40,7 +36,7 @@ protected void loadAudioStream() throws IOException, UnsupportedAudioFileExcepti System.out.println("No soportadp"); e.printStackTrace(); } catch (IOException e) { - System.out.println("IOExxception"); + System.out.println("LoadAudioStreamIOException: "+e.getMessage()); speakerAis = decodeRandomAccessMP4(ftrack); //e.printStackTrace(); } @@ -93,7 +89,7 @@ protected short getSecondsByBytes(int readedBytes) { } // Ver si duracion mostrada es real antes de entregar valor en segundos - @Override + /*@Override public long getDuration() { String strDuration = getProperty("duration"); return strDuration == null ? 0 : Long.parseLong(strDuration); @@ -106,7 +102,7 @@ public String getDurationAsString() { sec = sec-(min*60); return new StringBuilder().append(min) .append(':').append(sec < 10 ? '0'+sec:sec).toString(); - } + }*/ @Override public void seek(int seconds) throws Exception { @@ -116,20 +112,35 @@ public void seek(int seconds) throws Exception { public static void main(String[] args) throws UnsupportedAudioFileException, IOException, LineUnavailableException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { String strTrack = "/home/martin/AudioTesting/music/John Petrucci/" + "When_The_Keyboard_Breaks_Live_In_Chicago/Universal_Mind.m4a"; - Track track = new MP4Track(strTrack); + Track track = new M4ATrack(strTrack); //String strTrack = "/home/martin/AudioTesting/music/John Petrucci/" + // "When_The_Keyboard_Breaks_Live_In_Chicago/Universal_Mind.m4a"; //Track track = Track.getTrack(strTrack); //Track track = new PCMTrack(strTrack); new Thread(track).start(); - track.pause(); //System.out.println(track.getInfoSong()); + /* ID3TagBox idTag = new ID3TagBox(); Constructor constructor = MP4InputStream.class.getConstructor(RandomAccessFile.class); constructor.setAccessible(true); idTag.decode(constructor.newInstance(new RandomAccessFile(strTrack, "r"))); - System.out.println(Arrays.toString(idTag.getID3Data())); + System.out.println(Arrays.toString(idTag.getID3Data()));*/ + + + /*File file = new File(strTrack); + AudioFileFormat baseFileFormat = new MpegAudioFileReader().getAudioFileFormat(file); + Map properties = baseFileFormat.properties(); + long duration = Long.parseLong(properties.get("duration").toString()); + System.out.println(duration);*/ + /*File m4aFile = new File(strTrack); + + try (InputStream input = new FileInputStream(m4aFile)) { + AudioInfo audioInfo = new M4AInfo(input); + } catch (Exception e) { + System.out.println("No sirve"); + }*/ + } } diff --git a/src/org/orangeplayer/audio/formats/MP3Track.java b/src/org/orangeplayer/audio/formats/MP3Track.java index 066ff14..f23aa4f 100644 --- a/src/org/orangeplayer/audio/formats/MP3Track.java +++ b/src/org/orangeplayer/audio/formats/MP3Track.java @@ -40,7 +40,7 @@ protected short getSecondsByBytes(int readedBytes) { return (short) ((readedBytes * secs) / fLen); } - @Override + /*@Override public long getDuration() { String strDuration = getProperty("duration"); return strDuration == null ? 0 : @@ -54,7 +54,7 @@ public String getDurationAsString() { sec = sec-(min*60); return new StringBuilder().append(min) .append(':').append(sec < 10 ? '0'+sec:sec).toString(); - } + }*/ // Una vez obtenidas todas las duraciones por formato // el metodo seek sera universal diff --git a/src/org/orangeplayer/audio/formats/OGGTrack.java b/src/org/orangeplayer/audio/formats/OGGTrack.java index 78d9d41..21d3350 100644 --- a/src/org/orangeplayer/audio/formats/OGGTrack.java +++ b/src/org/orangeplayer/audio/formats/OGGTrack.java @@ -67,7 +67,7 @@ public void seek(int seconds) { } } - @Override + /*@Override public long getDuration() { try { return (long) new VorbisFile(ftrack.getCanonicalPath()).time_total(0); @@ -83,7 +83,7 @@ public String getDurationAsString() { sec = sec-(min*60); return new StringBuilder().append(min) .append(':').append(sec < 10 ? '0'+sec:sec).toString(); - } + }*/ @Override protected String getProperty(String key) { diff --git a/src/org/orangeplayer/audio/formats/PCMTrack.java b/src/org/orangeplayer/audio/formats/PCMTrack.java index 8c13031..3a3fdef 100644 --- a/src/org/orangeplayer/audio/formats/PCMTrack.java +++ b/src/org/orangeplayer/audio/formats/PCMTrack.java @@ -28,7 +28,7 @@ protected short getSecondsByBytes(int readedBytes) { return (short) ((readedBytes * secs) / fLen); } - @Override + /*@Override public long getDuration() { AudioFormat format = speakerAis.getFormat(); // Bits por sample, channels y sampleRate @@ -48,7 +48,7 @@ public String getDurationAsString() { sec = sec-(min*60); return new StringBuilder().append(min) .append(':').append(sec < 10 ? '0'+sec:sec).toString(); - } + }*/ @Override diff --git a/src/org/orangeplayer/audio/interfaces/PlayerControls.java b/src/org/orangeplayer/audio/interfaces/PlayerControls.java index 0275f27..cb379bc 100644 --- a/src/org/orangeplayer/audio/interfaces/PlayerControls.java +++ b/src/org/orangeplayer/audio/interfaces/PlayerControls.java @@ -6,6 +6,8 @@ public interface PlayerControls extends MusicControls { public void open(File sound); public void open(List listSounds); + public void addMusic(List listSounds); + public void addMusic(File musicFolder); public void playNext(); public void playPrevious(); public void shutdown(); diff --git a/src/org/orangeplayer/ontesting/AudioTaggerTest.java b/src/org/orangeplayer/ontesting/AudioTaggerTest.java new file mode 100644 index 0000000..c04b356 --- /dev/null +++ b/src/org/orangeplayer/ontesting/AudioTaggerTest.java @@ -0,0 +1,34 @@ +package org.orangeplayer.ontesting; + +import org.jaudiotagger.audio.AudioFile; +import org.jaudiotagger.audio.AudioFileIO; +import org.jaudiotagger.audio.exceptions.CannotReadException; +import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException; +import org.jaudiotagger.audio.exceptions.ReadOnlyFileException; +import org.jaudiotagger.tag.Tag; +import org.jaudiotagger.tag.TagException; + +import java.io.File; +import java.io.IOException; + +public class AudioTaggerTest { + public static void main(String[] args) throws TagException, ReadOnlyFileException, CannotReadException, InvalidAudioFrameException, IOException { + AudioFile file = AudioFileIO.read( + new File("/home/martin/AudioTesting/audio/au.mp3")); + File fCover = new File(file.getFile().getParent(), "cover.jpg"); + fCover.createNewFile(); + int seconds = file.getAudioHeader().getTrackLength(); + System.out.println(seconds); + Tag tag = file.getTag(); + //System.out.println("Tag: "+tag); + //System.out.println(tag.getFirst(FieldKey.COVER_ART)); + //Artwork cover = tag.getFirstArtwork(); + //Files.write(fCover.toPath(), cover.getBinaryData(), StandardOpenOption.TRUNCATE_EXISTING); + /*List listArtwork = tag.getArtworkList(); + + for (int i = 0; i < listArtwork.size(); i++) { + System.out.println(i+""+listArtwork.get(i).getDescription()); + }*/ + + } +} diff --git a/src/org/orangeplayer/main2/TestAAC2.java b/src/org/orangeplayer/ontesting/TestAAC2.java similarity index 85% rename from src/org/orangeplayer/main2/TestAAC2.java rename to src/org/orangeplayer/ontesting/TestAAC2.java index 9c7e113..845105d 100644 --- a/src/org/orangeplayer/main2/TestAAC2.java +++ b/src/org/orangeplayer/ontesting/TestAAC2.java @@ -1,4 +1,4 @@ -package org.orangeplayer.main2; +package org.orangeplayer.ontesting; import net.sourceforge.jaad.aac.AACException; import net.sourceforge.jaad.aac.Decoder; @@ -8,12 +8,8 @@ import net.sourceforge.jaad.mp4.api.AudioTrack; import net.sourceforge.jaad.mp4.api.Frame; import net.sourceforge.jaad.mp4.api.Movie; -import org.aucom.sound.Speaker; -import javax.sound.sampled.AudioFormat; -import javax.sound.sampled.AudioInputStream; -import javax.sound.sampled.LineUnavailableException; -import javax.sound.sampled.UnsupportedAudioFileException; +import javax.sound.sampled.*; import java.io.*; import java.util.List; @@ -23,8 +19,8 @@ public static void main(String[] args) throws IOException, LineUnavailableExcept //InputStream is = url.openStream(); String strTrack = - "/home/martin/AudioTesting/music/John Petrucci/When_The_Keyboard_Breaks_Live_In_Chicago/Universal_Mind.m4a"; - // "/home/martin/AudioTesting/audio/record.aac"; + //"/home/martin/AudioTesting/music/John Petrucci/When_The_Keyboard_Breaks_Live_In_Chicago/Universal_Mind.m4a"; + "/home/martin/AudioTesting/audio/aac3.aac"; //Toolkit toolkit = Toolkit.getPCMConvertedAudioInputStream(); File inputFile = new File(strTrack); //sound.createNewFile(); @@ -36,9 +32,9 @@ public static void main(String[] args) throws IOException, LineUnavailableExcept //Files.write(sound.toPath(), // buff.toArray(), StandardOpenOption.TRUNCATE_EXISTING); - AudioInputStream ais = decodeMP4(inputFile); + AudioInputStream ais = decodeAAC(inputFile); System.out.println("Decoded"); - Speaker speaker = new Speaker(ais.getFormat()); + /*Speaker speaker = new Speaker(ais.getFormat()); speaker.open(); System.out.println(ais.getFrameLength()); @@ -46,10 +42,10 @@ public static void main(String[] args) throws IOException, LineUnavailableExcept while (ais.read(buff) != -1) speaker.playAudio(buff); - - //File outFile = new File("/home/martin/AudioTesting/audio/waveout.wav"); - //outFile.createNewFile(); - //AudioSystem.write(ais, AudioFileFormat.Type.WAVE, outFile); +*/ + File outFile = new File("/home/martin/AudioTesting/audio/waveout.wav"); + outFile.createNewFile(); + AudioSystem.write(ais, AudioFileFormat.Type.WAVE, outFile); } private static AudioInputStream decodeAAC(File inputFile) throws AACException { diff --git a/src/org/orangeplayer/main2/TestPlayer.java b/src/org/orangeplayer/ontesting/TestPlayer.java similarity index 87% rename from src/org/orangeplayer/main2/TestPlayer.java rename to src/org/orangeplayer/ontesting/TestPlayer.java index 68ae58d..97faef2 100644 --- a/src/org/orangeplayer/main2/TestPlayer.java +++ b/src/org/orangeplayer/ontesting/TestPlayer.java @@ -1,10 +1,11 @@ -package org.orangeplayer.main2; +package org.orangeplayer.ontesting; import org.orangeplayer.audio.Player; import javax.sound.sampled.Control; import javax.sound.sampled.FloatControl; import javax.sound.sampled.SourceDataLine; +import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Scanner; @@ -16,8 +17,11 @@ public static void main(String[] args) throws IOException { //Player.newInstance(fPath); //Player player = Player.getPlayer(); - Player player = new Player(fPath); + Player player = new Player(); player.start(); + player.addMusic(new File(fPath)); + System.out.println("Sounds total: "+player.getSongsCount()); + Scanner scan = new Scanner(System.in); // /home/martin/AudioTesting/music/Alejandro Silva/1 - 1999/AlbumArtSmall.jpg // /home/martin/AudioTesting/music/NSYNC/NSYNC - No Strings Attached (2000)/ReadMe.txt @@ -39,15 +43,12 @@ public static void main(String[] args) throws IOException { player.jumpTrack(Integer.parseInt(line.substring(2))); player.playNext(); System.err.println("Antes de trackLine"); - trackLine = player.getTrackLine(); + trackLine = player.getCurrent().getTrackLine().getDriver(); System.err.println("Antes de controls"); System.out.println("Controls: "+Arrays.toString(trackLine.getControls())); Control pan = trackLine.getControl(FloatControl.Type.PAN); System.out.println("PAN: "+pan); - //System.out.println("Sample Rate: " + sample); - //System.out.println("Volume: " + volume); - case 'p': if (line.length() >= 3) player.jumpTrack((Integer.parseInt(line.substring(2))) * -1); @@ -76,12 +77,15 @@ public static void main(String[] args) throws IOException { player.reloadTracks(); break; case 'w': - System.out.println(player.getCurrentProgress()); + System.out.println(player.getTrackProgress()); break; case 'g': player.getCurrent().gotoSecond( Integer.parseInt(line.substring(2).trim())); break; + case 'c': + System.out.println(player.getSongsCount()); + break; } } catch (IllegalArgumentException e1) { System.err.println("Control no soportado"); diff --git a/src/org/orangeplayer/audio/TrackReflectInvoker.java b/test/TrackReflectInvoker.java similarity index 100% rename from src/org/orangeplayer/audio/TrackReflectInvoker.java rename to test/TrackReflectInvoker.java