Question

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();
 }
Was it helpful?

Solution

My guess is that the Video Live Wallpaper currently in circulation is using a totally different approach: decoding the media manually and drawing it frame by frame. I do not think this problem can be tackled using your simple method--otherwise more people would have already done it.

I assume you have this reference, but just in case: http://forum.xda-developers.com/showthread.php?t=804720 The explicit mention of differing video formats leads me to believe the developer is doing his own decoding... Good luck, George

OTHER TIPS

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.. :)

The reason this is happening is that MediaPlayer is calling the setKeepScreenOn method of the SurfaceHolder you are passing to it. You can get around this by creating a custom SurfaceHolder implementing Class and override setKeepScreenOn like this:

package com.justinbuser.videolivewallpapers;

import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.Surface;
import android.view.SurfaceHolder;

public class VideoSurfaceHolder implements SurfaceHolder {

    private SurfaceHolder surfaceHolder;

    public VideoSurfaceHolder(SurfaceHolder holder) {
        surfaceHolder = holder;
    }

    @Override
    public void addCallback(Callback callback) {
        surfaceHolder.addCallback(callback);
    }

    @Override
    public Surface getSurface() {
        return surfaceHolder.getSurface();
    }

    @Override
    public Rect getSurfaceFrame() {
        return surfaceHolder.getSurfaceFrame();
    }

    @Override
    public boolean isCreating() {
        return surfaceHolder.isCreating();
    }

    @Override
    public Canvas lockCanvas() {
        return surfaceHolder.lockCanvas();
    }

    @Override
    public Canvas lockCanvas(Rect dirty) {
        return surfaceHolder.lockCanvas(dirty);
    }

    @Override
    public void removeCallback(Callback callback) {
        surfaceHolder.removeCallback(callback);
    }

    @Override
    public void setFixedSize(int width, int height) {
        surfaceHolder.getSurface().setSize(width, height);
        surfaceHolder.setSizeFromLayout();
    }

    @Override
    public void setFormat(int format) {
        surfaceHolder.setFormat(format);
    }

    @Override
    public void setSizeFromLayout() {
        surfaceHolder.setSizeFromLayout();
    }

    @Override
    public void setType(int type) {
        surfaceHolder.setType(SURFACE_TYPE_PUSH_BUFFERS);
    }

    @Override
    public void setKeepScreenOn(boolean bool){
        //do nothing
    }

    @Override
    public void unlockCanvasAndPost(Canvas canvas) {
        surfaceHolder.unlockCanvasAndPost(canvas);
    }
}

Then when you would only have to make a minor change to the code you posted above, i.e. :

mp.setDisplay(new VideoSurfaceHolder(holder));

The problem you are going to have next is going to be that your Video will play but you will only hear audio. After several hours of tormented hair pulling etc... you would have realized that for whatever reason setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS) won't work properly. If you call it in onCreate then it works but surfaceCreated etc... never get called, if you call it in onSurfaceCreated then it's too late. Haven't solved that one myself yet but I'll keep you posted.

The error sounds like somewhere you have set the attribute, KeepScreenOn. It could be in your manifest, the xml defining your layout or somewhere in your main code. Follow the logcat output to find it and try removing it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top