Apwidgets media player not working in my android device

edited November 2014 in Android Mode

I started project with audio in android then I install Apwidgets library.
I start example in my tablet (Vandroid E1-B).. The sketch which I create using APDE show error message.. How tom make my sketch working??

import apwidgets.*;
APMediaPlayer player;
void setup() {
  player = new APMediaPlayer(this); //create new APMediaPlayer
  player.setMediaFile("50coins.mp3"); //set the file (files are in data folder)
  player.start(); //start play back
  player.setLooping(true); //restart playback end reached
  player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0
}
void draw() {
  background(0); //set black background
  text(player.getDuration(), 10, 10); //display the duration of the sound
  text(player.getCurrentPosition(), 10, 30); //display how far the sound has played
}

//The MediaPlayer must be released when the app closes
public void onDestroy() {
  super.onDestroy(); //call onDestroy on super class
  if (player!=null) { //must be checked because or else crash when return from landscape mode
    player.release(); //release the player
  }
}
Tagged:

Answers

  • classic problem with APIwidgets! try this:: (of course i have changed the mp3!!!) and also i think that it could be good to change (start at last) and to add (before starting) (according to android.doc)

    try {
                    player.prepare();
                } catch (IllegalStateException e) {
                    println("il y a un gros probleme!"
                    e.printStackTrace();
                } catch (IOException e) {
    
    
    
    import apwidgets.*;
    PMediaPlayer player;
    
    import android.media.MediaPlayer;
    void setup() {
      player = new PMediaPlayer(this); //create new APMediaPlayer
      player.setMediaFile("altastrada.mp3"); //set the file (files are in data folder)
      player.start(); //start play back
      player.setLooping(true); //restart playback end reached
      player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0
    }
    void draw() {
      background(0); //set black background
      text(player.getDuration(), 10, 10); //display the duration of the sound
      text(player.getCurrentPosition(), 10, 30); //display how far the sound has played
    }
    
    //The MediaPlayer must be released when the app closes
    public void onDestroy() {
      super.onDestroy(); //call onDestroy on super class
      if (player!=null) { //must be checked because or else crash when return from landscape mode
        player.release(); //release the player
      }
    }
    
  • @fakepuppet:: PS --- the import from android media player is not mandatory in your case --- if you want to see your text add also "fill(255)" in your draw() and some textSize()...

  • Thank you for you help @akenaton..
    Sorry, I don't have basic java programming.. I can't debug your code.. Your code shown error "unexpected token:try".. Next time I'll study Java since I love coding with Processing..

  • edited November 2014

    of course!!! i thought that you can easily complete; so, here the complete one, without the import from android and the try catch statement for on prepare(); that works::---of course change the name of the .mp3...

    import apwidgets.*;
    PMediaPlayer player;
    
    
    void setup() {
      orientation (PORTRAIT);
      player = new PMediaPlayer(this); //create new APMediaPlayer
      player.setMediaFile("altastrada.mp3"); //set the file (files are in data folder)
      player.setLooping(true); //restart playback end reached
      player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0
      player.start(); //start play back
    }
    void draw() {
      background(0); //set black background
      fill(255);
      textSize(24);
      text(player.getDuration(), 50, 100); //display the duration of the sound
      text(player.getCurrentPosition(), 10, 30); //display how far the sound has played
    }
    
    //The MediaPlayer must be released when the app closes
    public void onDestroy() {
      super.onDestroy(); //call onDestroy on super class
      if (player!=null) { //must be checked because or else crash when return from landscape mode
        player.release(); //release the player
      }
    }
    
  • edited November 2014

    I debug your code @akenaton.. PMediaPlayer isn't correct.. CMIIW.. So I change it into APMediaPlayer..
    When I compile again (in laptop), there is another problem.. error message "The function onDestroy() does not exist"
    I try debug in tablet using APDE, application still stopped working.. How to solve this onDestroy() stuff??

  • @fakepuppet::: PMedia player is correct!!!! --- APMediaPlayer is NOT correct---Don't refer to the old examples... I am sure; you can verify:::: try doing nothing except setup()(comment your draw and onDestroy()) and see: you can hear your sound and that it is looping (you cannot stop it of course without uninstalling rhe app on your device).... ----as for "on Destroy()", that is not normal, each android app knows that (life cycle activity) see here:: developer.android.com/reference/android/app/Activity.html and the player.release() is mandatory if you want that another app can use the player. Send the error code. Are you sure about the sound??? (true .mp3 in data folder) --- and of course changing my sound to yours!

  • I already put "sound.mp3" in data folder and check all permission in APDE
    @akenaton May you upload your sketch folder (archive as .zip)?? I still curious about my problem..

  • @fakepuppet: you have the code & the .zip would be exactly the same, which works perfectly for me; as for permissions i think that no permissions is needed for media (audio) player with a real device. Can you send the error code in console? Another thing could be with your tablet; i am using a phone, not a tablet & i don t know if it matters. As for a phone of course you have to put it in debug mode. Also: have you tried with the emulator? Send your error code & be more precise about android, processing & APWidgets version that you are using.

Sign In or Register to comment.