SDL port for Android SDK/NDK 1.6

Quickly share your Android Code Snippets here...

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Fri Mar 22, 2013 12:44 pm

I've enabled dummy CDROM in SDL, it should return success for SDL_Init(SDL_INIT_CDROM), and return zero available drives.

Also, I've reverted to using pre-compiled binaries for FFMPEG libraries, and tried to fix the changeAppSettings.sh script to work on MacOsX (the problem was with "sed -i" command). Could you please test it? Run
./changeAppSettings.sh -a
and check if it prints any errors.

If you want to create a release build, you should run
./build.sh release
The C/C++ code is already optimized even for debug builds (because building with -O0 causes internal compiler error in NDK toolchain), the only part that is optimized more in release build is Java code (also it won't put gdbserver binary into your .apk file). So you won't see much speed improvement.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Top

Re: SDL port for Android SDK/NDK 1.6

Postby Bjurr » Fri Mar 22, 2013 8:15 pm

pelya, I should hug you! :D

No more warnings on OSX, everything builds fine (using ballfield). The only thing I'm unsure that could've changed the output is that I just installed Macports...I'll re-run this on another "clean" machine when I'll have a chance, just to have a clear mind.

As a side note, I just noticed NDK r8e was released so I gave it a spin. So far everything seems to work.
Bjurr
Freshman
Freshman
 
Posts: 3
Joined: Thu Mar 21, 2013 3:45 am

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Fri Mar 22, 2013 9:16 pm

Hurray! For me it works too! :D
I have some trouble with the mouse pointer, screen aspect ratio (that I got more or less working) but the main thing that isn't ok is that the screen is moved some pixels down and right, and then my screen is cutted like 30 pixels on the right and down... strange :/

Edit: I added an screenshot with my Galaxy Nexus, and with two red lines drawn by me indicating the space the image is being displaced.
sdl_screen_movedcut.png
sdl_screen_movedcut.png (118.88 KiB) Viewed 537 times
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Fri Mar 22, 2013 10:01 pm

It seems that your application tries to use some uncommon screen resolution. Could you please check the adb logcat output, and find the log line with "SDL_SetVideoMode" text?
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Fri Mar 22, 2013 10:06 pm

Yup, this is it:

Code: Select all
I/libSDL  (13943): Changing curdir to "/storage/emulated/0/Android/data/org.funbox.musicboxtablet/files"
I/libSDL  (13943): Calling SDL_main("sdl")
I/libSDL  (13943): param 0 = "sdl"
V/libSDL  (13943): calling SDL_SetVideoMode(600, 450, 16, -1073741824)
I/libSDL  (13943): SDL_SetVideoMode(): application requested mode 640x480 OpenGL 0 HW 1 BPP 16
I/libSDL  (13943): SDL_SetVideoMode(): application requested hardware video mode - forcing software video mode
E/libSDL  (13943): ERROR: Setting the swap interval is not supported
E/libSDL  (13943): ERROR: Getting the swap interval is not supported
E/libSDL  (13943): ERROR: GL_GetAttribute not supported
I/libSDL  (13943): ANDROID_GL_GetProcAddress("glGetString"): 0x400cbcc0
V/libSDL  (13943): SDL_SetVideoMode(): Requested mode: 600x450x16, obtained mode 640x480x16
V/libSDL  (13943): SDL_SetVideoMode(): returning surface 0x5bf21cf8

It goes to 640x480, which is bigger, but... shouldn't it start painting at top-left?

This app is targeted at an Android tablet with a 1024x600 resolution (minus 48pixels of the button menu it is 1024x552), it's not a conventional resolution, so... will I have problems with it?
Yup, I have to update the graphics still, they're 4:3 :p

I have tried with 640x480 and it's fine, there isn't any cutting/moving at all.
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Fri Mar 22, 2013 10:43 pm

You can use your device native resolution, there will be no cutting. If you'll be always using 600x450, the easiest way would be to add a custom resolution inside file project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c:297
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Top

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Fri Mar 22, 2013 10:44 pm

oh, thanks! thanks a lot!
You're my hero this week :D
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Mon Mar 25, 2013 2:32 pm

Quick question!
Is there a way to open a webbrowser? And closing it then.
Or where should be the best place to put a jni call from c++ to java in order to create a webview and control it?

OR... if you know how to play swf files...
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Mon Mar 25, 2013 2:42 pm

#include <stdlib.h or unistd.h, I do not remember>
system( "am start -a android.intent.action.VIEW -d 'http://www.stackoverflow.com'" );
I don't know how to close it, since it will be launched as an external app, and you cannot control external app.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Mon Mar 25, 2013 4:18 pm

Wow! It works! But I need to play a local swf file and I can't see to get to it, I tried with different mime types and it doesn't play :(
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Mon Mar 25, 2013 6:08 pm

You can try to create a local html file, that will load your swf file from disk. However if user has Chrome installed, it won't work, because Chrome disallows loading files from local filesystem to webpage. So you'll need to use your own WebView, you can use function SDL_ANDROID_JniEnv() to get JNI object (there was another way, without SDL, but I don't remember it). Also, Flash is not supported in Android 4.2 or newer, and it's not installed by default in Cyanogenmod, so if it's something important, you'd better just use a video file.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Mon Mar 25, 2013 9:58 pm

Oh, I see...
Thanks!
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Sun Mar 31, 2013 3:34 am

Hi again! I'm using ffmpeg and sndfile... and they don't work at all :(

With ffmpeg this fails to open the file, when above I tested it for opening:
err = avformat_open_input(&format_context, filename.c_str(), NULL, NULL);

And with sndfile when opening a file it crashes:
sFile1 = sf_open(getFilename(AID_Stage03Do).c_str(), SFM_READ, &sInfo1);

Do you have any idea of what is happening?

BTW, in order to my code compile with ffmpeg I had to define this macro: #define __STDC_CONSTANT_MACROS
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby Mixu » Sun Mar 31, 2013 8:06 pm

And when creating a jni callback to java... it isn't called:

--- inside a C++ module
// JNI OnLoad
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
{
g_JavaVM = vm;
return JNI_VERSION_1_6;
}

void VideoManager::playVideo(int num) {

JNIEnv* env = NULL;
g_JavaVM->GetEnv((void**)&env, JNI_VERSION_1_6);
g_JavaVM->AttachCurrentThread(&env, NULL);
jclass JavaClass = (jclass) env->NewGlobalRef(env->FindClass("org/funbox/musicboxtablet/MainActivity"));
jmethodID player = env->GetMethodID(JavaClass, "playVideo", "(I)V");
jmethodID c_id = env->GetMethodID(JavaClass, "<init>", "()V");
jobject obj = env->NewObject(JavaClass, c_id);
env->CallVoidMethod( obj, player, num );
}

---- and I modified the MainActivity.java with this function:

public void playVideo(int num) {


VideoView videoHolder = new VideoView(this);
setContentView(videoHolder);

Uri video = null;

if (num==1) video = Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw.p1);
if (num==2) video = Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw.p2);
if (num==3) video = Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw.p3);
if (num==4) video = Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw.p4);
if (num==5) video = Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw.p5);

videoHolder.setVideoURI(video);
videoHolder.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
setContentView(_videoLayout);
}
});

videoHolder.start();
videoHolder.setOnTouchListener(new OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
((VideoView)v).stopPlayback();
setContentView(_videoLayout);
return true;
}
});

}

-----
I'm a little desperate, sorry if I spam this too much.
Mixu
Junior Developer
Junior Developer
 
Posts: 20
Joined: Wed Mar 20, 2013 1:41 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Mon Apr 01, 2013 3:38 pm

I'll try to compile some working example for ffmpeg and sndfile libs. I'm not sure about JNI code, there are many things that might go wrong. Here's an example of working code that calls Java methods using JNI.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Top
PreviousNext

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 2 guests