On Thu, Aug 13, 2009 at 1:41 PM, mjoselli<[email protected]> wrote:
>
> 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.
If you look at the system log, you'll see exactly where and why it crashed.
> 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());
This view you just created isn't attached to anything. You should put
a SurfaceView in your layout xml.
Also, for most cases you can probably just use VideoView and have it
handle much of the details for you.
> mp.setDisplay((SurfaceHolder) mPreview.getHolder());
>
> mPreview.setDrawingCacheEnabled(true);
>
>
> mp.start();
>
>
> /* HEre is some test that I tried with VideoView
> mVideoView = new VideoView(context);
Again, just creating a view doesn't attach it to the window/view
hierarchy. You should add the view to your layout xml.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---