Android Development AirPlay Server

Source: Internet
Author: User

The development of AirPlay Server on Android is mainly referenced and modified Droidairplay Project, and airplay protocol

1, download the Droidairplay

2, Eclipse Create a new Android project, and add the JRE Library (to prevent errors, only compiled use), the project using the following several jar packages, self-download, do not forget to join the network and storage permissions

base64-2.3.8. Jar Bcprov-ext-jdk16-1.46. Jardd-plist.jar jmdns-3.4.0. Jarnetty-3.2.4  . Final.jar (the above jar package can be downloaded from search.maven.org search)

3. Copy the package under SRC of the Droidairplay project to SRC under the new project

4, new activity, start the service using the following code in the OnCreate method

Airplayserver DWA = airplayserver.getistance ();d wa.setrtspport (8998); New Thread (new  Runnable () {    @Override    publicvoid  run () {                Dwa.run ( );    }}). Start ();

5, need to modify the place, are in nz.co.iswe.android.airplay.audio.AudioOutputQueue This class, reference to this article

1, instantiation of Audiotrack
Create the Audiotrack //audiotrack = new Audiotrack (Streamtype, Samplerateinhz, Channelconfig, Audioformat, buffersizeinbytes, mode); New Audiotrack (Streamtype, Samplerateinhz, Audioformat.channel_configuration_stereo, Audioformat, BufferSizeInBytes, mode); // Fixme
2. Data acquisition
byte byttemp = 0x00; if(convertunsignedtosigned) {/*the line expects signed PCM samples, so we must * convert the unsigned PCM samples to signed.     * Note that this is only affects the high bytes! */      for(inti=0; i < samplesconverted.length; i + = 2) {Samplesconverted[i]= (byte) ((Samplesconverted[i] & 0xff)-0x80); //Add by VilleByttemp =Samplesconverted[i]; Samplesconverted[i]= Samplesconverted[i + 1]; Samplesconverted[i+ 1] =byttemp; //End    }}

6, after the modification should be able to run, but after using the iphone connection to play the concert found that the volume is not adjusted, because Android Audiotrack maximum volume of 1.0, and according to the Airplay Protocol document description

float value representing the audio attenuation in DB. A value of–144 means the audio is muted. Then it goes from–30 to 0.

Need to modify  nz co iswe android airplay audio the following place (approximately 744 rows),

if ("Volume". Equals (name)) {    ifnull) {         float vol = math.abs ( Float.parsefloat (value));         = (float) (1.0-(vol/29.0));        Audiooutputqueue.setrequestedvolume (vol);}   }

Then modify the Setstereovolume method of the audiooutputqueue

// comment out the following two lines leftvolume= = Audiotrack.getmaxvolume ();

8, modify the device name, the default iphone will search for a device named localhost (wlan0) , by modifying the Nz.co.iswe.android.airplay.AirPlayServer, You can customize the device name

157 rows
String hostName = "Dwairplay"; // networkutils.gethostutils ();

9, the above code big God F2 test pass, but in C8650 this old machine found no sound, through log guessing is the equipment processing ability is insufficient, do not know is this reason ...

Android Development AirPlay Server

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: info-contact@alibabacloud.com 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.