简体   繁体   中英

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM