gBroutin / gstreamer-java

Automatically exported from code.google.com/p/gstreamer-java
0 stars 0 forks source link

[Windows] PlayBin.setInputFile does not work with filenames containing specials characters and spaces #46

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

With the sample code below:

PlayBin playBin = new PlayBin("Test");      
playBin.setVideoSink(ElementFactory.make("fakesink", "videosink"));
playBin.setInputFile(new File("D:\\01-¿ Exorde Baratté _.ogg"));
playBin.play();

What is the expected output? What do you see instead?

Bus.ERROR() reports "Could not open file "D:\01-¿ Exorde Baratté _.ogg" for
reading.". No audio playback.

Have you tried to verify this is a gstreamer-java specific issue, and not a
problem with the gstreamer framework itself?

Others applications using GStreamer are able to read the file.

What version of the product are you using? On what operating system?

GStreamer 0.10.28 on Windows XP SP2. Under Linux, the same file plays fine
with the above sample code.

Please provide any additional information below.

I was able to play this file with the following code :

String encodedFileName = URLEncoder.encode("D:\\01-¿ Exorde Baratté _.ogg",
"UTF-8");
encodedFileName = encodedFileName.replaceAll("\\+", "%20");
playBin.set("uri", "file:///" + encodedFileName);

URLEncoder.encode() encodes specials chars and changes spaces to "+". At
this point, Bus.ERROR() would report "Resource not found.". Changing the
"+" to "%20" does the trick and allow playback.

Original issue reported on code.google.com by J.Devauc...@gmail.com on 18 May 2010 at 11:35

GoogleCodeExporter commented 8 years ago
Thanks for the report. Could you help us isolate this to special characters in 
file
name vs. space in file name:

1. Can you add a file.exists() test before calling playBin.setInputFile()
2. Can you rename your file to be without any special characters, but contain 
one or
two space in its name

Original comment by tsha...@gmail.com on 19 May 2010 at 6:31

GoogleCodeExporter commented 8 years ago
With this sample code:

Gst.init("Test", args);

PlayBin playBin = new PlayBin("Test");
playBin.setVideoSink(ElementFactory.make("fakesink", "videosink"));

playBin.getBus().connect(new Bus.ERROR() {              
    @Override
    public void errorMessage(GstObject arg0, int arg1, String arg2) {
        System.out.println(arg2);                   
    }
});

String fileName = "D:\\01-¿ Exorde Baratté _.ogg";

File file = new File(fileName);

if (file.exists()) {
    System.out.println("File exists. uri=" + file.toURI());

        playBin.setInputFile(file);
        playBin.setState(State.PLAYING);
    Gst.main();
    playBin.setState(State.NULL);
} else {
    System.out.println("File does not exists.");
}

Test 1: fileName = "D:\\01-¿ Exorde Baratté _.ogg" (specials chars and spaces)
Output: File exists. uri=file:/D:/01-¿%20Exorde%20Baratté%20_.ogg
Bus.ERROR(): Could not open file "D:\01-¿ Exorde Baratté _.ogg" for reading.
No Playback.

Test 2: fileName = "D:\\01- Exorde Baratt.ogg" (no specials chars, spaces)
Output: File exists. uri=file:/D:/01-%20Exorde%20Baratt.ogg
Bus.ERROR(): Nothing.
Playback Ok.

Test 3: fileName = "D:\\01-¿ExordeBaratté_.ogg" (specials chars, no spaces)
Output: File exists. uri=file:/D:/01-¿ExordeBaratté_.ogg
Bus.ERROR(): Could not open file "D:\01-¿ExordeBaratté_.ogg" for reading.
No playback.

So it seems to only be related to special characters. I did a lot of tests 
yesterday,
i may have been confused. The thing is that if you try my workaround (using
URLEncoder.encode()) without replacing "+" by "%20", test 3 (specials chars, no
spaces) works well. So i believe GStreamer expects URI where special characters 
are
properly encoded and spaces are encoded as %20.

Hope this help !

Original comment by J.Devauc...@gmail.com on 19 May 2010 at 12:11

GoogleCodeExporter commented 8 years ago
One more thing, i said that another application using GStreamer plays the file, 
but i
did not look how it handles this case. The facts are this application 
(Clementine
Music Player, http://code.google.com/p/clementine-player/) uses GStreamer, does 
not
use GStreamer-Java, and plays this file, but it can have some tricky code to 
handle
this. So it could be a GStreamer issue.

Original comment by J.Devauc...@gmail.com on 19 May 2010 at 12:23

GoogleCodeExporter commented 8 years ago
does a simple java code contains:
new File("D:\\01-¿ Exorde Baratté _.ogg")
can read the file on windows?
if not then it has nothing to do with gstreamer-java, but java on windows.

Original comment by lfar...@gmail.com on 27 May 2010 at 4:32

GoogleCodeExporter commented 8 years ago
imho it has nothing to do with gstreamer-java since it's a simple java problem.

Original comment by lfar...@gmail.com on 28 May 2010 at 7:59

GoogleCodeExporter commented 8 years ago
Hu? PlayBin has a method setInputFile(File), i give it a perfectly valid File
instance and it does not work...

Anyway, apart from the workaround i gave in my first comment, i do not have a 
better
solution, do you have a better suggestion ?

Original comment by J.Devauc...@gmail.com on 28 May 2010 at 10:25

GoogleCodeExporter commented 8 years ago
try running your application with system property -Djna.encoding=utf-8

Original comment by tsha...@gmail.com on 15 Jun 2010 at 9:47

GoogleCodeExporter commented 8 years ago
It works! Many thanks for pointing this out.

Thanks for your work on gstreamer-java.

Original comment by J.Devauc...@gmail.com on 15 Jun 2010 at 11:12