# Android Processing App

**URL:** https://discourse.processing.org/t/android-processing-app/20267
**Category:** Processing for Android
**Tags:** homework
**Created:** [April 29, 2020, 2:04pm UTC](https://discourse.processing.org/t/android-processing-app/20267 "2020-04-29T14:04:44Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)
#### Post date: [April 29, 2020, 2:04pm UTC](https://discourse.processing.org/t/android-processing-app/20267/1 "2020-04-29T14:04:44Z")

</div>

English: Hello I wanted to ask how you can play a video on the phone in the processing app. I have to do something similar to netflix. xD

Deutsch: Hallo ich wollte mal fragen wie man am Handy in der Processing App ein Video abspielen kann. ich muss sowas ähnliches machen wie netflix. xD

~DRogner 🧤

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [April 29, 2020, 2:46pm UTC](https://discourse.processing.org/t/android-processing-app/20267/2 "2020-04-29T14:46:28Z")

</div>

@Rogo ===  
It depends of your needs (there are a lot of ways for doing that); yet, as for beginning see here: [https://discourse.processing.org/t/need-help-with-play-video/20260/3](https://discourse.processing.org/t/need-help-with-play-video/20260/3)

---

<div class="post-metadata">

### Author: ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)
#### Post date: [April 29, 2020, 2:52pm UTC](https://discourse.processing.org/t/android-processing-app/20267/3 "2020-04-29T14:52:57Z")

</div>

I have only been using processing for a few days now, can you show me how to do this with the video so I can learn best if someone fools me and if I don’t understand it I can always ask

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [April 29, 2020, 3:07pm UTC](https://discourse.processing.org/t/android-processing-app/20267/4 "2020-04-29T15:07:38Z")

</div>

@Rogo Why do you mark your own question as a solution?

---

<div class="post-metadata">

### Author: ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)
#### Post date: [April 29, 2020, 3:47pm UTC](https://discourse.processing.org/t/android-processing-app/20267/5 "2020-04-29T15:47:10Z")

</div>

I dont know 🙂 sorry

---

<div class="post-metadata">

### Author: ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)
#### Post date: [April 29, 2020, 3:48pm UTC](https://discourse.processing.org/t/android-processing-app/20267/6 "2020-04-29T15:48:59Z")

</div>

Hay @noel, can you maybe help me with my question?

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [April 29, 2020, 4:00pm UTC](https://discourse.processing.org/t/android-processing-app/20267/7 "2020-04-29T16:00:09Z")

</div>

Have you read the topic @akenaton suggested?

---

<div class="post-metadata">

### Author: ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)
#### Post date: [April 29, 2020, 4:30pm UTC](https://discourse.processing.org/t/android-processing-app/20267/8 "2020-04-29T16:30:37Z")

</div>

No wait please 😂

---

<div class="post-metadata">

### Author: ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)
#### Post date: [April 29, 2020, 4:34pm UTC](https://discourse.processing.org/t/android-processing-app/20267/9 "2020-04-29T16:34:15Z")

</div>

Oh okay thanks wait i try it

---

<div class="post-metadata">

### Author: ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)
#### Post date: [April 29, 2020, 5:29pm UTC](https://discourse.processing.org/t/android-processing-app/20267/10 "2020-04-29T17:29:52Z")

</div>

@noel @noel

Hay, i mean this in my Post

```auto
import android.media.MediaMetadataRetriever;
import android.os.Looper;
import android.app.Activity;
import android.view.ViewGroup;
import android.view.View;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.media.MediaMetadataRetriever;
import android.media.MediaPlayer;
import android.content.res.Resources;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.content.Context;
import java.util.concurrent.TimeUnit; 
int t, video_x, video_y, video_width, video_height, video_w, video_h;
int[] bx_val;
String video_title;
String[] txt = {"Play", "Pause", "Rewind"};
float duration, slider_length, slider_x, slider_y, bw, bs, bys;
double mp_current_position;
boolean on_start = true;
color bg, bc, ds, glow; 
AssetFileDescriptor afd;
Context context;
Activity act;
SurfaceView mySurface;
SurfaceHolder mSurfaceHolder;
MediaMetadataRetriever metaRetriever;
MediaPlayer mp;
Slider slider; 
void setup() { 
  orientation(PORTRAIT); 
  bg = color(255, 165, 0); 
  ds = color(50, 50, 0);
  glow = color(0, 220, 220);
  bc = color(255, 100, 0);
  background(bg);
  video_title = "vid.mp4";
  video_width = 3*width/4;
  video_height = height/3; 
  video_x = (displayWidth-video_width)/2; 
  video_y = (displayHeight-video_height)/4;
  slider_length = video_width;
  slider_x = (width - slider_length)/2; 
  slider_y = video_y+video_height+height/20; 
  slider = new Slider(slider_x, slider_y, slider_length); 
  slider.update();
  textSize(28*displayDensity*1200/height); 
  stroke(ds); 
  strokeWeight(3); 
  bx_val = new int[3];
  if (mousePressed) for (int i = 0; i < 3; i++) { 
    bs = slider_length/12;
    bw = 5*slider_length/6/3; 
    float xu = i*(bw+bs)+slider_x; 
    bx_val[i] = int(xu);
    fill(bc); 
    bys = video_y+video_height;
    rect(xu, bys+height/9, bw, height/30, 12); 
    fill(ds); 
    text(txt[i], xu+width/30, bys+height/7.4);
  }
  initVideo(); 
  mp.start(); 
  textSize(24*displayDensity*1200/height); 
  String str = String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes((long) duration), TimeUnit.MILLISECONDS.toSeconds((long) duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) duration))); 
  text(str, slider_x+slider_length-textWidth(str), video_y+video_height+height/30); 
  displayTime();
} 
void draw() { 
  if (on_start) { 
    mp_current_position = mp.getCurrentPosition(); 
    if (mp_current_position > 2) { 
      on_start = false; 
      mp.pause();
    }
  } 
  if (mousePressed) { 
    mp_current_position = mp.getCurrentPosition(); 
    if (mouseX >= slider_x && mouseX <= slider_x+slider_length) { 
      if (mouseY >= slider_y-height/30 && mouseY <= slider_y+height/30) { 
        slider.update();
      }
    }
  } 
  if (mp.isPlaying()) { 
    mp_current_position = mp.getCurrentPosition(); 
    displayTime(); 
    slider.setPosition(mp_current_position);
  }
} 
void displayTime() {
  textSize(24*displayDensity*1200/height); 
  String str = String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes((long) mp_current_position), TimeUnit.MILLISECONDS.toSeconds((long) mp_current_position) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) mp_current_position))); 
  fill(bg); 
  noStroke(); 
  float th = textAscent()+textDescent(); 
  rect(slider_x-15, video_y+video_height+20, textWidth(str)+30, th); 
  fill(ds); 
  text(str, slider_x, video_y+video_height+height/30);
} 
void settings() { 
  fullScreen ();
} 
void mousePressed() { 
  for (int i = 0; i < 3; i++) { 
    if (mouseX > bx_val[i] && mouseX < bx_val[i]+bw+bs && mouseY > bys+height/9 && mouseY < bys+height/9+height/30) { 
      switch(i) { 
      case 0: 
        if (mp.isPlaying() == false) mp.start(); 
        break; 
      case 1: 
        if (mp.isPlaying() == true) mp.pause(); 
        break; 
      case 2: 
        mp.pause(); 
        slider.setPosition(slider_x); 
        mp.seekTo(0); 
        break;
      }
    }
  }
} 
public class Slider { 
  float slider_x, slider_y, slider_length, slider_position; 
  Slider(float _x, float _y, float _l) { 
    slider_x = _x; 
    slider_y = _y; 
    slider_length = _l;
  } 
  void update() { 
    float sp = map(mouseX-slider_x, 0.0, slider_length, 0.0, duration); 
    if (!on_start) mp.seekTo(int(sp)); 
    drawSlider(); 
    float loc = mouseX; 
    if (on_start) loc = slider_x; 
    ellipse(loc, slider_y+3, 25, 25);
  } 
  void setPosition(double mp_current_position) { 
    drawSlider(); 
    slider_position = map((float)mp_current_position, 0.0, duration, 0.0, slider_length-1); 
    ellipse(slider_x+slider_position, slider_y+3, 25, 25);
  } 
  void drawSlider() { 
    fill(bg); 
    noStroke(); 
    rect(slider_x-15, slider_y-15, slider_length+40, 40); 
    fill(ds); 
    rect(slider_x, slider_y, slider_length, 5); 
    strokeWeight(3); 
    stroke(glow);
  } 
  float getVal() { 
    return slider_position;
  }
} 
void initVideo() { 
  act = this.getActivity(); 
  context = act.getApplicationContext(); 
  Looper.prepare(); 
  mp = new MediaPlayer(); 
  try { 
    afd = context.getAssets().openFd(video_title); 
    MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever(); 
    metaRetriever.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); 
    String h = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); 
    String w = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); 
    video_w = int(w); 
    video_h = int(h); 
    println("Original video height = "+h+" width = "+w); 
    mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); 
    mp.prepare(); 
    duration = mp.getDuration(); 
    println("length = "+afd.getLength()); 
    println("duration = "+mp.getDuration()); 
    println("startOffset = "+afd.getStartOffset() );
  } 
  catch (IOException e) { 
    e.printStackTrace();
  } 
  mySurface = new SurfaceView(act); 
  mSurfaceHolder = mySurface.getHolder(); 
  mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
  mSurfaceHolder.addCallback(new SurfaceHolder.Callback() { 
    @Override public void surfaceCreated(SurfaceHolder surfaceHolder) { 
      mp.setDisplay(surfaceHolder); 
      println("Surface created");
    } 
    @Override public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) { 
      mp.setDisplay(surfaceHolder);
      println("Surface changed");
    }
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) { 
      println("Surface destroid");
    }
  } 
  ); 
  act.runOnUiThread(new Runnable() { 
    public void run() { 
      mSurfaceHolder = mySurface.getHolder(); 
      mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 
      act.addContentView(mySurface, new ViewGroup.LayoutParams(video_width, video_height)); 
      mySurface.setZOrderOnTop(true); 
      mySurface.setX(video_x); 
      mySurface.setY(video_y);
    }
  } 
  );
} 
void onStop() { 
  if (mp!=null) { 
    mp.release(); 
    mp = null; 
    println ("Stopped");
  } 
  super.onStop() ;
}

```

why is my video not displayed?

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [April 29, 2020, 5:38pm UTC](https://discourse.processing.org/t/android-processing-app/20267/11 "2020-04-29T17:38:28Z")

</div>

> [@Rogo](#):
>
> why is my video not displayed?

Did you change the (video\_title = “vid.mp4”; ) with your video name located in the data folder?

---

<div class="post-metadata">

### Author: ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)
#### Post date: [April 29, 2020, 5:44pm UTC](https://discourse.processing.org/t/android-processing-app/20267/12 "2020-04-29T17:44:17Z")

</div>

Yes 👇🏻

 ![Screenshot_20200429-194114_My Files](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/da62418da85fe9791868595805b6420677bbcf0e.jpeg)

HERE THE ERRORS

 ![Screenshot_20200429-194811_APDE](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/068f871890200fbe226affd458aed11997a6e837.jpeg)

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [April 29, 2020, 5:50pm UTC](https://discourse.processing.org/t/android-processing-app/20267/13 "2020-04-29T17:50:33Z")

</div>

If this is homework you are not supposed to replicate someones other code. It’s posted there only as a guide line. May I ask if the teacher mentioned Processing for Android to do this task?  
The error means that the file was not found.

---

<div class="post-metadata">

### Author: ![Rogo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rogo/32/12349_2.png) [@Rogo](https://discourse.processing.org/u/Rogo)
#### Post date: [April 29, 2020, 5:54pm UTC](https://discourse.processing.org/t/android-processing-app/20267/14 "2020-04-29T17:54:08Z")

</div>

why is the video not found?

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [April 29, 2020, 6:06pm UTC](https://discourse.processing.org/t/android-processing-app/20267/15 "2020-04-29T18:06:26Z")

</div>

You didn’t answer my question!  
Further more if you use this code on APDE, you have to run it in “app” mode.

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [April 30, 2020, 9:38am UTC](https://discourse.processing.org/t/android-processing-app/20267/16 "2020-04-30T09:38:52Z")

</div>

@Rogo ===

I dont work with APDE; yet i tested the code you have put, and it works; the video is found…

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [April 30, 2020, 10:00am UTC](https://discourse.processing.org/t/android-processing-app/20267/17 "2020-04-30T10:00:37Z")

</div>

It’s because he tested it in “Preview mode” instead of “App mode” (A very fast compiling mode, codeanticode is planning to implement it on P4A PC as well)  
I can see it on the image he posted.

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [April 30, 2020, 12:55pm UTC](https://discourse.processing.org/t/android-processing-app/20267/18 "2020-04-30T12:55:17Z")

</div>

@noel === ah! ok now i can understand
