Android video as a live wallpaper

user593443 picture user593443 · Jan 28, 2011 · Viewed 7.9k times · Source

i am trying to put video as a live wallpaper. I am using media player for that. i can get SurfaceHolder and i can give that holder to the media player. But its not working for me, its giving me following exception

LogCat Exception Detail

ERROR/AndroidRuntime(302): java.lang.UnsupportedOperationException: Wallpapers do not support keep screen on

if i dont give holder to the media player it works, but i can hear only audio. I saw one application VideoLiveWallpaper , which set video as a live wallpaper, so it can be possible, may be i am missing something . I am pasting the code, any help on this will be appreciated.

Code Snippet

public void surfaceCreated(SurfaceHolder holder) {
  // TODO Auto-generated method stub

 holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  mp=MediaPlayer.create(getApplicationContext(), R.raw.sample);
  mp.setDisplay(holder);
  mp.start();
 }

Answer

Rankush Kumar picture Rankush Kumar · Apr 25, 2013

Instead of using **mediaPlayer.setDisplay(surfaceHolder)** you can use **mediaPlayer.setSurface(surfaceHolder.getSurface())**..

It will not give any kind of conflicts with the attribute KeepScreenOn.

NJOY.. :)