Skip to content

Commit

Permalink
Merge pull request #8 from umjammer/1.9.11
Browse files Browse the repository at this point in the history
fix #7
  • Loading branch information
umjammer authored Mar 11, 2022
2 parents be5221a + 97b2cdf commit a0ccaea
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven
name: Java CI

on:
push:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[![Maven Package](https://github.com/umjammer/mp3spi/actions/workflows/maven-publish.yml/badge.svg)](https://github.com/umjammer/mp3spi/actions/workflows/maven-publish.yml) [![Java CI with Maven](https://github.com/umjammer/mp3spi/workflows/Java%20CI%20with%20Maven/badge.svg)](https://github.com/umjammer/mp3spi/actions) [![Parent](https://img.shields.io/badge/Parent-vavi--sound--sandbox-pink)](https://github.com/umjammer/vavi-sound-sandbox)
[![Maven Package](https://github.com/umjammer/mp3spi/actions/workflows/maven-publish.yml/badge.svg)](https://github.com/umjammer/mp3spi/actions/workflows/maven-publish.yml)
[![Java CI](https://github.com/umjammer/mp3spi/workflows/Java%20CI%20with%20Maven/badge.svg)](https://github.com/umjammer/mp3spi/actions)
[![Parent](https://img.shields.io/badge/Parent-vavi--sound--sandbox-pink)](https://github.com/umjammer/vavi-sound-sandbox)

# MP3SPI

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

<groupId>net.javazoom</groupId>
<artifactId>mp3spi</artifactId>
<version>1.9.10</version>
<version>1.9.11</version>

<properties>
<tritonus.groupId>org.tritonus</tritonus.groupId>
<tritonus.version>0.3.10</tritonus.version>
<tritonus.version>0.3.11</tritonus.version>
</properties>

<distributionManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
Expand Down Expand Up @@ -93,13 +91,13 @@ public class MpegAudioFileReader extends TAudioFileReader
private static final String[] id3v1genres;

static {
try {
Path path = Paths.get(MpegAudioFileReader.class.getResource("/genres.properties").toURI());
List<String> genres = Files.readAllLines(path);
id3v1genres = genres.toArray(new String[genres.size()]);
} catch (IOException | URISyntaxException e) {
throw new IllegalStateException(e);
Scanner scanner = new Scanner(MpegAudioFileReader.class.getResourceAsStream("/genres.properties"));
List<String> genres = new ArrayList<>();
while (scanner.hasNextLine()) {
genres.add(scanner.nextLine());
}
scanner.close();
id3v1genres = genres.toArray(new String[genres.size()]);
}

public MpegAudioFileReader()
Expand Down
36 changes: 35 additions & 1 deletion src/test/java/Test3.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import java.io.BufferedInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import javax.sound.sampled.AudioFileFormat;
Expand All @@ -22,6 +24,7 @@
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.spi.AudioFileReader;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
Expand All @@ -33,6 +36,7 @@
import vavi.util.properties.annotation.PropsEntity;

import static javazoom.spi.mpeg.sampled.file.PlayerTest.volume;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static vavix.util.DelayedWorker.later;

Expand Down Expand Up @@ -73,7 +77,11 @@ void setup() {
@DisplayName("just play")
void test2() throws Exception {
AudioInputStream originalAudioInputStream = AudioSystem.getAudioInputStream(Paths.get(inFile).toFile());
AudioFormat originalAudioFormat = originalAudioInputStream.getFormat();
play(originalAudioInputStream);
}

void play(AudioInputStream originalAudioInputStream) throws Exception {
AudioFormat originalAudioFormat = originalAudioInputStream.getFormat();
Debug.println(originalAudioFormat);
AudioFormat targetAudioFormat = new AudioFormat( //PCM
originalAudioFormat.getSampleRate(),
Expand Down Expand Up @@ -124,6 +132,32 @@ void test3() throws Exception {
}
}

@Test
@SuppressWarnings({ "unchecked", "rawtypes", "restriction" })
void test4() throws Exception {
List<AudioFileReader> providers = (List) com.sun.media.sound.JDK13Services.getProviders(AudioFileReader.class);
providers.forEach(System.err::println);
assertTrue(providers.stream().map(o -> o.getClass().getName()).anyMatch(s -> s.contains("javazoom.spi.mpeg.sampled.file.MpegAudioFileReader")));
}

@Test
void test5() throws Exception {
String file = "src/test/resources/test2.mp3";
InputStream is = new BufferedInputStream(Files.newInputStream(Paths.get(file)));
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(is);
play(audioInputStream);
}

// TODO wip
@Test
void test6() throws Exception {
String file = "src/test/resources/test2.mp3";
InputStream is = new BufferedInputStream(Files.newInputStream(Paths.get(file)));
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(is);
String genre = (String) audioInputStream.getFormat().getProperty("mp3.id3tag.genre");
Debug.println("genre: " + genre);
}

@Test
@Disabled
@DisplayName("test all mp3s in your itumes music")
Expand Down
Binary file added src/test/resources/test2.mp3
Binary file not shown.

0 comments on commit a0ccaea

Please sign in to comment.