textchanged event processing2

edited May 2014 in Android Mode

hi, im trying to do a gps android application on a xperia z. i'm playing a music file (wav) when i reach a location. the problem i encounter now is that when i reached the 1st area where the audio is been played, it play perfectly but when i reach the 2nd spot, the audio doesn't change, it just stuck with the 1st location audio. i'm using APMediaPlayer. i check online for a few days, i've tried "clear();" & "stop();" but it doesn't work. So i was wondering is there any textchanged event function for processing2?

(audio)my code:

void mousePressed(){
  if (bus_01 < 50) // setting the distance to 50m
  {
    player = new APMediaPlayer(this); //create new APMediaPlayer
    player.setMediaFile("north.wav"); //set the file (files are in data folder)
    player.start(); 
    player.setLooping(false); //restart playback end reached
    player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0//start play back

  }
  else if (bus_02 < 50)// setting the distance to 50m
  {
    player = new APMediaPlayer(this); //create new APMediaPlayer
    player.setMediaFile("south.wav"); //set the file (files are in data folder)
    player.start(); 
    player.setLooping(false); //restart playback end reached
    player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0//start play back
  }
}

Answers

  • It will be much easier to help you if you post an MCVE instead of a disconnected snippet.

    But in order to debug your code, you need to answer a few questions: what are the values of bus_01 and bus_02 when you reach the second spot? Which if statement does the code enter?

    Notice that you're using an if/else if statement, so if the code enters the first if statement, it will ignore the second one.

  • thank you so much for replying me i'm so sorry, i didn't know how i'm suppose to post on forum. But i think you catch what i'm trying to say. about the bus_01 and bus_02 is actually the distance from my location to the point i have set as my north and south.

    //please don't ask why i import so much stuff, i'm not sure too but i don't think it affects the programme right?
        import ketai.sensors.*; 
        import android.media.*;
        import android.provider.Settings;
        import android.content.res.*;
        import android.content.Context;
        import android.app.*;
        import java.lang.Object.*;
        import android.app.AlarmManager.*;
        import apwidgets.*;
    
    
        APMediaPlayer player;
    
        double longitude, latitude, accuracy, bus_01, bus_02;
    
        KetaiLocation location;
        Location north, south;
    
    
            void setup() 
            { 
              frameRate(30);
    
              orientation(LANDSCAPE);
              textAlign(CENTER, CENTER);
              textSize(50);
    
              north =new Location("North"); // Example location: North
              north.setLatitude(1.338029); //Latitude
              north.setLongitude(103.819340); //Longitude
    
              south=new Location("South"); // Example location: South
              south.setLatitude(1.334933);
              south.setLongitude(103.817932);
    
              bus_01 = location.getLocation().distanceTo(north);
              bus_02 = location.getLocation().distanceTo(south);
            }
    
        void mousePressed(){
          if (bus_01 < 50) // setting the distance to 50m
          {
            player = new APMediaPlayer(this); //create new APMediaPlayer
            player.setMediaFile("north.wav"); //set the file (files are in data folder)
            player.start(); 
            player.setLooping(false); //restart playback end reached
            player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0//start play back
    
          }
          else if (bus_02 < 50)// setting the distance to 50m
          {
            player = new APMediaPlayer(this); //create new APMediaPlayer
            player.setMediaFile("south.wav"); //set the file (files are in data folder)
            player.start(); 
            player.setLooping(false); //restart playback end reached
            player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0//start play back
          }
        }
    
    
        void draw() 
        {
          background(78, 93, 75);
    
    
          if (latitude >1.3380)
            text("Location:  North\n" +
              "Latitude: " + latitude + "\n" +
              "Longtitude: " + longitude + "\n" +
              "Accuracy: " + accuracy + "\n" +
              "Distance To Next Bus Stop: "+ location.getLocation().distanceTo(north) + " m\n" + 
              "Provider: " + location.getProvider(), 20, 0, width, height);
    
    
          else if (latitude >1.3349  && latitude <1.3380)
            text("Location: South \n" + 
              "Latitude: " + latitude + "\n" + 
              "Longitude: " + longitude + "\n" + 
              "Accuracy: " + accuracy + "\n" +
              "Distance To Next Bus Stop: "+ location.getLocation().distanceTo(south) + " m\n" + 
              "Provider: " + location.getProvider(), 20, 0, width, height);
    
    
          else 
    
            text("Error \n" +
            "Please check your location settings.", 20, 0, width, height);
        }
    
        void onResume()
        {
          super.onResume();
          location = new KetaiLocation(this);
        }
    
        void onPause()
        {
          super.onPause();
        }
    
    
        void onLocationEvent(Location _location)
        {
          //print out the location object
          println("onLocation event: " + _location.toString());
          longitude = _location.getLongitude();
          latitude = _location.getLatitude();
          accuracy = _location.getAccuracy();
        }
    

    "Notice that you're using an if/else if statement, so if the code enters the first if statement, it will ignore the second one." - i didn't know about this, what can i use to make it so that it will run through the everytime the gps refresh?

  • You should add some print statements to better understand what this code is doing. It will only ever enter ONE of those if statements. If the first if statement evaluates to true, it doesn't even look at the second one. Is that the behavior you want?

  • nope, i want it to go through both, meaning other it ring, it release the music which it is holding and run through both again. but i have no idea how to do it

  • I recommend reading the basic tutorials on if statements: http://www.processing.org/reference/else.html http://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html http://staticvoidgames.com/tutorials/basicConcepts/IfStatements.jsp

    If that doesn't clear it up, I recommend creating an MCVE that tests how if/else statements work.

    If you're still confused, post that MCVE here, and we'll go from there.

Sign In or Register to comment.