Hello All,

I am trying to create a video player using a custom interface (with a
lot of images).

I am moving from J2ME to android apps.

In J2ME I just create a canvas and set the video to draw to the
canvas...

but now with android I am not able to do it...

So I have seen that I can create a View of my own and draw on it. So I
create a view, load images and create a video and a surface for the
video.

When I call videoSurface.draw() the application crashes.

So i tried to videoSurface.getDrawingCache() to get a bitmap and draw
it. But the bitmap is always null.

How can I do it?

Thanks,


The code is bellow

package com.example.helloandroid;

import java.io.IOException;
import java.util.ArrayList;


import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Picture;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Message;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.TextView;
import android.widget.VideoView;

public class canvasView extends View{
        Drawable fundo;
        MediaPlayer mp;
        SurfaceView mPreview;
        VideoView mVideoView;
        Bitmap drawVideo = null;
        Paint mPaint = new Paint();
        public canvasView(Context context) {
                super(context);
                // TODO Auto-generated constructor stub
                int resID = getResources().getIdentifier
("com.example.helloandroid:drawable/fundo", null, null);
                fundo = getResources().getDrawable(resID);
                fundo.setBounds(0, 0, 480, 320);
                mp = new MediaPlayer();
            try {
                        
mp.setDataSource("rtsp://10.223.246.33/broadcast/timtv/cnn.3gp");
                        mp.prepare();
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                mPreview  = new SurfaceView(this.getContext());
                mp.setDisplay((SurfaceHolder) mPreview.getHolder());

                mPreview.setDrawingCacheEnabled(true);


            mp.start();


                /* HEre is some test that I tried with VideoView
                mVideoView = new VideoView(context);

                
mVideoView.setVideoPath("rtsp://10.223.246.33/broadcast/timtv/cnn.
3gp");

                mVideoView.getHolder().setFixedSize(176, 144);

                mVideoView.start();

                mVideoView.buildDrawingCache();

                ArrayList<View> array = new ArrayList<View>(1);
                array.add(mVideoView);

                this.addFocusables(array, 0);

                mVideoView.requestFocus();

                mVideoView.bringToFront();

*/

        }
        int runned = 0;
        private RefreshHandler mRedrawHandler = new RefreshHandler();

    class RefreshHandler extends Handler {

        @Override
        public void handleMessage(Message msg) {

                canvasView.this.invalidate();
                canvasView.this.update();


        }

        public void sleep(long delayMillis) {
                this.removeMessages(0);
            sendMessageDelayed(obtainMessage(0), delayMillis);
        }
    };

        public void update(){
                mPreview.buildDrawingCache();
                drawVideo = mPreview.getDrawingCache();

                mRedrawHandler.sleep(10);

        }


    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);

                if(drawVideo!= null){

                        canvas.drawBitmap(drawVideo, 0,0, null);
                        mPreview.destroyDrawingCache();

                        canvas.drawText("not null", 100, 120, mPaint);
                }


                //mVideoView.draw(canvas);
        }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to