Ask if you can directly call the Android library for audio playback

Source: Internet
Author: User

Problem description
Question: Can I call Android system in C + + code, I wrote a test program in C + +, Call the 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--->>>> 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 library for audio playback

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.