Problem description
Question: Can I call Android system libmedia.so in C + + code, I wrote a test program in C + +, Call the libmedia.so in the Mediaplayer.cpp method for audio playback, can be compiled, can also be executed in the Android system's set-top box, but the prepare () method has been blocked, ask the big God how to solve ah, give some ideas? Here is the test code:
#include <stdio.h>
#include <stdlib.h>
#include <mediaplayer.h>
using namespace Android;
int main ()
{
int iRet = 0;
MediaPlayer *p= new MediaPlayer ();
IRet = P->setdatasource ("/data/j2me/phoneme-cache/061075.midi", NULL);
if (0! = IRet)
{
printf ("[setdatasource] IRet =%d\n", iRet);
}
IRet = P->setaudiostreamtype (3);
if (0! = IRet)
{
printf ("[setaudiostreamtype] IRet =%d\n", iRet);
}
IRet = P->prepare ();
if (0! = IRet)
{
printf ("[Prepare] IRet =%d\n", iRet);
}
IRet = P->start ();
if (0! = IRet)
{
printf ("[start] IRet =%d\n", iRet);
}
P->stop ();
return 0;
}
Solutions 1
Reference 3 Floor Dengxuguang's reply:
Quote: Referring to the reply of the 2 floor guoyoulei520:
Quote: Referring to the reply of the 1 floor Dengxuguang:
Ask bearer pointing ah, tangled for several days, no longer solve will collapse ...
You look at the Android source code in the Libmedia call process ...
Look, the flow from top to bottom is MediaPlayer--->libmedia_jni.so---->libmedia.so------->libmediaplayerserver.so------> ALSA Library.
The audio playback process is Setdatasource () \prepare () \start () ....
But a direct call through the so library is problematic.
Ask for advice
The Java layer's code for playing media also has setdatasource. Prepare. The corresponding process you have seen it ....
Is it a privilege or other problem? Look at the prepare function, and under what circumstances will it block?
Ask if you can directly call the Android Libmedia.so library for audio playback