Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Playing Movie Files In A Live Wallpaper

Is this even possible? I have tried using the MediaPlayer but it throws a NullPointerException on the MediaPlayer object. I can get audio to work but video wont.

 mp=MediaPlayer.create(getApplicationContext(), R.raw.sample);
 mp.start();
 mp.setOnCompletionListener(new OnCompletionListener() 
 {
     public void onCompletion(MediaPlayer mp) {
          mp.release();
          playing = false;
     }
 });

the sample is of .mp4 type.

Anyone have an idea of why this is happening or have a suggestion for another method of getting videos to be played?

like image 683
Matthew Avatar asked May 03 '11 01:05

Matthew


People also ask

Can Android support live wallpaper?

The Android operating system allows for live wallpapers, which are animated or interactive scenes that work as your phone's home screen image.


2 Answers

You can use the following code

VideoView videoView;
    VideoView = (VideoView) findViewById (R.id.txt1);
    videoView.setVideoPath(path);
    videoView.setVisibility(VideoView.VISIBLE);
videoView.start();

i have tried to play mp4 on my emulator but it was not showing video but when i tried on device it work fine.

like image 133
Salman Avatar answered Nov 04 '22 06:11

Salman


Haven't tried that before but I think you can use vlcj framework that's totally free and can play effectively almost any type of video (and of course plays .mp4 video files) .I can't give you any code in android because have never worked with android but I know java and and it just works.So here what i use in Java:

NativeLibrary.addSearchPath("libvlc",path); //To set path of libvlc
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);//To import libvlc
//The path can be a folder in your android project.All the files needed are in vlc player installation folder.so yes you have to install vlc in your computer to get those files but just once.
canvas = new WindowsCanvas();
panel.add(canvas);//panel is like your VideoView
canvas.setVisible(true);
canvas.setBackground(Color.black);

mediaPlayerFactory = new MediaPlayerFactory();
player12 = mediaPlayerFactory.newEmbeddedMediaPlayer();
CanvasVideoSurface videoSurface = mediaPlayerFactory.newVideoSurface(canvas);
player12.setVideoSurface(videoSurface);
player12.setPlaySubItems(true);
player12.startMedia(yourVideoPath); 

player12.setAspectRatio(""+panel.getWidth()+":"+panel.getHeight()); //Those two lines are for your video to be adusted in your panel or better to your VideoView
player12.setCropGeometry(""+panel.getWidth()+":"+panel.getHeight()); 

The jar files you have to include in your classpath are jna-3.4.0.jar,platform-3.4.0.jar,vlcj-2.1.0.jar

like image 38
PeGiannOS Avatar answered Nov 04 '22 05:11

PeGiannOS