22
\$\begingroup\$

Is there a way to play videos with LibGDX?

I want to put a video as my splash screen in Android, but I dont want to use the Android SDK, because I am using LibGDX and I am almost finished :/

\$\endgroup\$
1

3 Answers 3

12
\$\begingroup\$

Playing video with LibGDX has been defined as out of scope for the project. So no, you cannot play videos using LibGDX.

This does not preclude the possibility of writing code specific to Android to play videos though. It just means your application won't maintain the portability of LibGDX.

\$\endgroup\$
7
  • \$\begingroup\$ :( ok thanks for that answer :/ I suppose that I have to use Android SDK, thanks :) \$\endgroup\$
    – Rudy_TM
    Jun 14, 2012 at 16:01
  • 4
    \$\begingroup\$ I did it with Android :) I created a new Activity and a new Layout, and when the video finishes its playback, I start the activity that has the call to libGDX \$\endgroup\$
    – Rudy_TM
    Jun 14, 2012 at 17:17
  • \$\begingroup\$ Nice! That was fast, I guess it wasn't too hard to do after all. \$\endgroup\$
    – House
    Jun 14, 2012 at 17:18
  • 1
    \$\begingroup\$ @Rudy_TM please add this as the accepted answer -- that you got around it with a new Activity. That will help others who have the same question later. \$\endgroup\$
    – ashes999
    Jun 14, 2012 at 17:34
  • \$\begingroup\$ It's pretty easy to write platform specific code in libgdx, so just because it doesn't support video out of the box doesn't mean it can't be done, as your answer implies. \$\endgroup\$
    – Matsemann
    Jun 14, 2012 at 17:46
20
\$\begingroup\$

As Byte56 said, in libGDX you cannot play videos :( so i did this:

I created a new activity "SplashScreen"

public class SplashScreen extends Activity implements OnCompletionListener
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.splash);
        String fileName = "android.resource://"+  getPackageName() +"/raw/video";

         VideoView vv = (VideoView) this.findViewById(R.id.surface);
         vv.setVideoURI(Uri.parse(fileName));
         vv.setOnCompletionListener(this);
         vv.start();

    }

    @Override
    public void onCompletion(MediaPlayer mp) 
    {
        // TODO Auto-generated method stub
        Intent intent = new Intent(this, libgdx.class);
        startActivity(intent);      
        finish();
    }
}

In the "onCompletion" method, I use the intent to call my new activity where the "initialize" call for the libGDX engine to work

And a new layout for the videoView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <VideoView
        android:id="@+id/surface"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center" >

    </VideoView>

</LinearLayout>
\$\endgroup\$
8
  • 2
    \$\begingroup\$ +1 Thanks for posting this answer, it will be helpful to future visitors. \$\endgroup\$
    – House
    Jun 14, 2012 at 17:56
  • 1
    \$\begingroup\$ You are welcome :) I spent two days trying different things XD and this was the last one :P \$\endgroup\$
    – Rudy_TM
    Jun 14, 2012 at 18:02
  • 2
    \$\begingroup\$ It's always the last one right? I guess because you stop looking after that :p. Also congrats on nearly being done! \$\endgroup\$
    – House
    Jun 14, 2012 at 18:05
  • \$\begingroup\$ @Rudy_TM libgdx.class give me an error (libgdx cannot be resolved to a type), how to fix it ? \$\endgroup\$
    – LeSam
    Feb 7, 2014 at 21:18
  • 2
    \$\begingroup\$ @G3tinmybelly in your manifest change your splash screen to the launcher activity instead of the MainActivity, \$\endgroup\$
    – Rudy_TM
    Jun 24, 2014 at 16:49
-1
\$\begingroup\$

This is the way to play: libname is "indiespot-media-0.8.09.jar" which you can get here.

How to use:

  1. Download full zip
  2. Copy lib folder in the root of project (ffmpeg will be opened by lib with path ./lib/ffmpeg/ffmpeg@os postfix@)
player = new MoviePlayer(videoFile);
Texure playerTexture = new Texture(
  player.movie.width(), 
  player.movie.height(), 
  Pixmap.Format.RGBA8888) {

  @Override
  public void bind() {
    Gdx.gl.glBindTexture(0, player.textureHandle);
  }
};
  1. use playerTexture as usual texture
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .