1

I read this code to play video files using xuggler as a library.When i run this code , the video without sound plays.Why is that ?

If not what should i do to play audio with video.?

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328
saplingPro
  • 20,769
  • 53
  • 137
  • 195

2 Answers2

1

My guess is that you have a missing audio codec. I've had this same issue but vice versa; the sound played but the video didn't.

Christian
  • 27,509
  • 17
  • 111
  • 155
  • How to test if you guessed right ? If i miss what should i do ? – saplingPro Jul 31 '11 at 17:17
  • Let me tell you that audio is played when i run the code to decode only audio. – saplingPro Jul 31 '11 at 17:22
  • does the code given there play normally on **your** machine ? – saplingPro Jul 31 '11 at 18:02
  • To test, you can install a codec pack. But since you said you decoded audio successfully, I'm starting to have my doubts. As to running the code, I'm sorry but I didn't test it out. The above is just a piece of information. – Christian Jul 31 '11 at 19:45
  • Can you please test it on your machine ? I just wanted to check if the audio controls have been given in the program or not !. – saplingPro Jul 31 '11 at 19:55
  • It's a good guess, but I'm afraid it's wrong... there is no code in that example to decode any audio streams and play them! See my answer :) – Michael Berry Aug 01 '11 at 21:28
1

Quite simply, it's because that code doesn't play any audio. It was never written to do so!

If you want to play audio and video, check out the example here:

http://xuggle.googlecode.com/svn/trunk/java/xuggle-xuggler/src/com/xuggle/xuggler/demos/DecodeAndPlayAudioAndVideo.java

The question to me suggests that you've just grabbed the source without looking at the tutorials - I'd strongly suggest doing so so you can understand the code behind what's going on rather than just throwing it in there and expecting it to work - especially if you're planning on using Xuggler in any great depth!

As a further note, if all you want to do is play videos I probably wouldn't advise using Xuggler because it's just not really designed for that sort of thing. Sure it will play them, but you have to manage all the sync issues yourself (which the above example doesn't do a great job of), it will only use your CPU and therefore really eat into its consumption especially if you're doing things like HD video, and the sheer amount of background code is just overkill (getting the streams, finding the stream IDs, extracting each packet, determining the type of the packet, dealing with it appropriately, managing errors, etc. etc.) It's a great piece of software, but if you're only using it to play stuff then it'll probably give you far more trouble than its worth.

Instead I'd advocate having a play with VLCJ - it's a bit complicated to get set up to work reliably (out of process players are required for rock solid stability) but when you've got that far it plays near any file type under the sun and manages all the issues above for you much, much better than you'll ever cope with by hand!

Michael Berry
  • 70,193
  • 21
  • 157
  • 216
  • for playing audio do you recommend xuggler ? Is `JLayer` able to play videos ? – saplingPro Aug 02 '11 at 06:58
  • Well again, you can use it for that but it works on the same low level. As far as I know JLayer can't play videos no - for that you'll definitely have to resort to some native component. If you use VLCJ it'll play back whatever VLC can manage, which is just about anything - audio or video. – Michael Berry Aug 02 '11 at 08:19