Playing video on Android

edited November 2014 in Android Mode

I have a simple video player Processing sketch that plays some videos.

The issue is it won't run under Android due to the lack of video.processing library not being available.

How would I play a video in Processing in such a way that it would work on Android devices?

Thanks for any advice.

Phil

Tagged:

Answers

  • I'm pretty sure that APWidgets has a video player.

  • Thanks Calsign, I looked at APWidgets but couldn't get it playing a video yet.

    Have you had success playing video?

    I think the first issue I have is how to give it the path of the video, any idea?

    Thanks.

    Phil

  • edited May 2014 Answer ✓

    I have not used APWidgets personally, but it has worked for others before.

    Have you looked at the APVideoView Example (I'm pretty sure it comes with the distribution as well...)?

    If it still doesn't work, please post the code that you are having difficulty with.

  • The video example is great but it takes the mp4 from from the SD card, my Android phone doesn't have an SD card and cannot figure out how to specify an mp4.

    I can get a .wav file to play from my /data/ folder but if I put an mp4 in there my app just errors.

    I think it could be a path issue but not sure.

    Thanks.

    Phil

  • package com.akenaton.travail;

    import android.support.v7.app.ActionBar.LayoutParams;
    import android.support.v7.app.ActionBarActivity;
    import android.app.Activity;
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.Canvas;
    import android.media.MediaMetadataRetriever;
    import android.media.MediaPlayer;
    import android.media.MediaPlayer.OnPreparedListener;
    import android.net.Uri;
    import android.os.Bundle;
    import android.util.DisplayMetrics;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.MediaController;
    import android.widget.RelativeLayout;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.widget.VideoView;
    import java.nio.Buffer;
    import java.util.HashMap;
    
    
    
    
    
    
    
    public class TravailACTIVITE extends Activity {
        int cp = 0;
        int hauteur;
        int largeur;
        int[] tableauCouleurs;
        int K = 0;
        TextView t = null;
        VideoView vd = null;
        public String uri;
        public Bitmap mFrameBitmap;
        @Override
        protected  void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_travail_activite);
    
            //pour lancer la video
    
            VideoView vd = (VideoView)findViewById(R.id.video);
            uri = "android.resource://" + getPackageName() + "/" + R.raw.my_video_file;
            vd.setVideoURI(Uri.parse(uri));
            //MediaController mc = new MediaController(this);//pour avoir un controleur
            //vd.setMediaController(mc);
            vd.setOnPreparedListener (new OnPreparedListener() {  //pour mettre en boucle                  
    
                public void onPrepared(MediaPlayer mp) {
                    mp.setLooping(true);
                }
            });
    
    
    
            vd.start();//ici la video a démarré, on s'occupe du texte
    
    
            TextView t = (TextView) findViewById(R.id.texte_toast);
            t.setText("est ce que ce texte s'écrira sur la video");
            //pour positionner le texte sur la video avec des coordonnées
            RelativeLayout.LayoutParams position = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            position.leftMargin = 40;
            position.topMargin  = 150;
            t.setLayoutParams(position);
    
    }
    
    
    
    
    
    
    
    
    
    
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
    
            getMenuInflater().inflate(R.menu.travail_activite, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }
    }
    
    class MyCustomView extends View{
    
        /*
        these viewWidth and viewHeight class variables
        will be used to store this CustomView's width and height dimensions
        as obtained from the automatic onSizeChanged() method call
         */
       /* int viewWidth = 0;
        int viewHeight = 0;
    
        public MyCustomView(Context context) {
                super(context);
        }
    
        /*
        This onSizeChanged() method gets called automatically
        BEFORE the view gets layed out or drawn for the first time.
        It alse gets called when the view's orientation changes
        or gets resized etc. This is the method that does the trick.
        In this method, you get your view's updated dimensions.
        Then you should store these dimension values into
        the global int variables that are declared above.
        Later, you can call these global variables to read what
        is the new width or height of the object
        --------- thanks to kgiannakakis May 25 '10 at 9:18
        --------- http://ow.ly/44hzw 
        */
        /*
        @Override
        protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld){
                super.onSizeChanged(xNew, yNew, xOld, yOld);
                viewWidth = xNew;
                viewHeight = yNew;
                /*
                these viewWidth and viewHeight variables
                are the global int variables
                that were declared above
                */
      //  }
    
        /*
        This method gets called automatically
        when the view needs to get drawn onto the layout
        */
    
        /*
        @Override
        protected void onDraw(Canvas canvas){
                super.onDraw(canvas);
                /*
                finally, once the view gets drawn on to the screen
                we can retrieve the dimension values
                as stored in the global variables declared above
                */
               // String msg = "width: " + viewWidth + "height: " + viewHeight;
                //System.out.println(msg);
      //  }*//
    //}*/
    
  • of course that is using eclipse && android!!!

  • I guess you need to can change the video to individual frames and playback the frames... that's what I did!

Sign In or Register to comment.