Trying to do a commercial project using jPCT-AE

Started by azid, December 13, 2012, 05:20:17 PM

Previous topic - Next topic

azid

Hi,

I am developing something big  ::)  using jPCT-AE. Please visit

http://www.vhearttech.com

Feel free to leave comments. Latest updates are in the blog.

Azid

azid

This is more difficult than I imagine. For 3 days I tried to play background music (a 1.4mb Mp3) upon startup of the app but it either hang or crash. About a dozen ways were used. Funny thing is, if the app is just for playing sound it runs ok. When used with 3d it crashed. Used mediaplayer, soundpool as well as propriety libraries. Maybe the 3d and sound together caused out of memory error?. The following were tried:

Crash with 3d, standalone sound plays ok.
1.  Paulscode's Android to play ogg file (with jni, c++, etc, file was converted to 1.5mb ogg)
2.  http://androidatteja.blogspot.com/2009/04/android-mediaplayer-example.html
3.  http://www.badprog.com/android-mediaplayer-example-of-playing-sounds
4.  http://stackoverflow.com/questions/9108642/androidplay-audio-files-using-single-mediaplayer-object-and-also-display-images?rq=1
5.  http://lab-programming.blogspot.com/2012/01/how-to-work-around-android-mediaplayer.html
6.  http://developer.android.com/training/managing-audio/volume-playback.html
7.  etc etc

Help please. Should 3d and sound be separated by its own thread? How to do it? How to estimate memory usage? Is the sound linked to hardware volume keys?

EgonOlsen

This is what i'm doing and i never had a problem with that (ignore the ContentManager reference...it's just a wrapper around AssetManager.openFD(...):


package com.threed.jpct.games.rpg;

import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;

import com.threed.jpct.Logger;

public class MusicPlayer {

private static MediaPlayer mp = null;

public static void playMusic() {

if (mp != null) {
return;
}


try {
mp = new MediaPlayer();
AssetFileDescriptor afd = ((ContentManagerImpl)ManagerProvider.getManager(ContentManager.class)).getFD("music/Yesterbreeze.mp3"); // hacky cast...
mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
mp.prepare();
mp.setLooping(true);
mp.setVolume(0.28f, 0.28f);
mp.start();
} catch (Exception e) {
Logger.log("Unable to start music!");
Logger.log(e);
}

}

public static void stopMusic() {
if (mp != null) {
mp.stop();
mp = null;
}
}

}



Make sure to use OGG. MP3 playback fails/hangs on some devices.

azid

#3
Just figured it out!. The background sound won't  play if mediaplayer is set in onStop, onResume and onPause. The only code required is in onDestroy (stop the sound when app is killed). The standalones all set it in all ons coz most have buttons to play and pause. Very simple code too, just a few lines for background sound to play continuously.

For mp3 format, i'm more familiar with mp3 than ogg and I can fine tune the audio such as resample it to VBR to reduce size without losing too much quality. The mp3 was 1.4mb, ogg was 1.5mb but resampled mp3 is now 710kb for a 92sec of audio (minimal loss). Besides, i may test the java code with j2objc soon and i heard that ios don't do ogg.

Btw, lets look at the code:


..
import android.media.MediaPlayer;   // 1st line needed
..
public class Your3Dapp extends Activity {   
..
MediaPlayer mediaPlayer;     //  2nd line
int soundID = 1;                    //  optional
..
protected void onCreate(Bundle savedInstanceState) {
--
         mediaPlayer = MediaPlayer.create(this, R.raw.the_sound);   //  3rd line

mediaPlayer.start();                  //  4th line
      mediaPlayer.setLooping(true);    //  optional
      mediaPlayer.setVolume(100,100);   //  optional
..
protected void onPause() {      //  leave this alone
Logger.log("onPause");
super.onPause();
mGLView.onPause();
}

@Override
protected void onResume() {
Logger.log("onResume");
super.onResume();
mGLView.onResume();
}

protected void onStop() {              //  leave this alone
Logger.log("onStop");
super.onStop();
}

protected void onDestroy() {
if(mediaPlayer != null)      //  5th line needed
{
try{
mediaPlayer.stop();        //  6th line
mediaPlayer.release();    //  7th line
}finally {
mediaPlayer = null;   //  8th line
}
super.onDestroy();
}
}
..

azid

I am getting this message on logcat:

01-09 15:41:34.946: I/Choreographer(403): Skipped 277 frames!  The application may be doing too much work on its main thread.

Should I be worried? Should I separate certain tasks on different thread? like collision, for example?

Its running very slow on emulator (0.5 - 2 fps) but relatively ok on Galaxy Tab P1000 at 9-51 fps depending on how many objects seen.

p.s. Thank you so much for all the help so far. I'm still learning jPCT-AE and and am lovin it.

EgonOlsen

Quote from: azid on January 09, 2013, 04:52:12 PM
Should I be worried? Should I separate certain tasks on different thread? like collision, for example?
I don't think so. I think this has something to do with apps that are blocking the UI thread. It get this from all kinds of apps, including the ones from google...

azid

#6
Hajj3D for Android Alpha Trial ready for download. Feel free to test the app and please give us your feedback.

The app was tested on Samsung Galaxy S3. Runs OK. Crowd runs too fast though. There's also blue bands on certain objects such as floors. The pic shows the blue bands. It seems that that's where mipmapping occurs. No blue bands on Galaxy Tab, Galaxy S or Experia Arc though.


[attachment deleted by admin]

EgonOlsen

Is there a way to try it without registering? About the blue banding: Might be a driver problem with mip-map generation. There's a setting in Config (internalMipmapCreation). Try to set it to true and see if that helps.

EgonOlsen

The Galaxy Note has the same blue banding issue. It's most likely a driver issue of some kind. Try the config setting mentioned above and it that doesn't help, try to adjust color depth/size of that texture to see if that helps. Am i supposed to be able to control my movement? I'm just moving around in circles with no obvious control.
And don't forget to make the music stop when the app stops....i had a singing phone after returning to the home screen... ;)

azid

Controls: Single touch anywhere on screen to move forward. Double simultaneous touch anywhere on screen to turn left. Triple simultaneous touch  anywhere on screen to turn right. Untouch to continue moving.

Audio still playing after app stop: Audio should stop too when I press back or home button to stop the app. Will do more test on this.

Blue band: Will get either an S3 or note before making any changes.