Programming/Non programming

Monday, March 29, 2010

Android: Basic study

Android:

Introduction, installation and basic starter guide can be learnt from the following link, which i have found very good links for Android learners:

http://developerlife.com/tutorials/?p=300

http://www.helloandroid.com

Cheers!

M.P.Prabakar
Senior Systems Analyst


Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

iPhone:Hide Status bar

iPhone:

How to hide status bar from the view on iPhone development?

Add the below code in your AppDelegate "applicationDidFinishLaunching" method.


[[UIApplication sharedApplication] setStatusBarHidden:YES];


Cheers!

M.P.Prabakar
Senior Systems Analyst


Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

Android: Play PCM(.WAV) audio buffer using AudioTrack

Android:

Play Audio sound .PCM(.WAV) buffer using AudioTrack class

The following is the code samples shows this task:

1. First way:

Play the sound directly without reading file with some amount of buffer by buffer. It is
useful to play short sounds.

private void PlayShortAudioFileViaAudioTrack(String filePath) throws IOException
{
// We keep temporarily filePath globally as we have only two sample sounds now..
if (filePath==null)
return;

//Reading the file..
byte[] byteData = null;
File file = null;
file = new File(filePath); // for ex. path= "/sdcard/samplesound.pcm" or "/sdcard/samplesound.wav"
byteData = new byte[(int) file.length()];
FileInputStream in = null;
try {
in = new FileInputStream( file );
in.read( byteData );
in.close();

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Set and push to audio track..
int intSize = android.media.AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_8BIT);
AudioTrack at = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_8BIT, intSize, AudioTrack.MODE_STREAM);
if (at!=null) {
at.play();
// Write the byte array to the track
at.write(byteData, 0, byteData.length);
at.stop();
at.release();
}
else
Log.d("TCAudio", "audio track is not initialised ");

}


2. Second way:

Play the sound by reading file with some amount of buffer by buffer. It is useful to play
bigger size sounds.
Reading by 512 kb buffer and writing into track.

private void PlayAudioFileViaAudioTrack(String filePath) throws IOException
{
// We keep temporarily filePath globally as we have only two sample sounds now..
if (filePath==null)
return;

int intSize = android.media.AudioTrack.getMinBufferSize(44100, AudioFormat.CHANNEL_CONFIGURATION_STEREO,
AudioFormat.ENCODING_PCM_16BIT);

AudioTrack at = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_CONFIGURATION_STEREO,
AudioFormat.ENCODING_PCM_16BIT, intSize, AudioTrack.MODE_STREAM);


if (at==null){
Log.d("TCAudio", "audio track is not initialised ");
return;
}

int count = 512 * 1024; // 512 kb
//Reading the file..
byte[] byteData = null;
File file = null;
file = new File(filePath);

byteData = new byte[(int)count];
FileInputStream in = null;
try {
in = new FileInputStream( file );

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

int bytesread = 0, ret = 0;
int size = (int) file.length();
at.play();
while (bytesread < size) { ret = in.read( byteData,0, count); if (ret != -1) { // Write the byte array to the track at.write(byteData,0, ret); bytesread += ret; } else break; } in.close(); at.stop(); at.release(); }

Thank you followers !

Cheers,
M.P.Prabakar
Senior Systems Analyst

Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

iPhone:Types of Touch events

iPhone:

The following are the touch events are available on iPhone development

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

}

Thank you for followers!

Cheers,

M.P.Prabakar
Senior Systems Analyst


Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

iPhone:Touch event for particular UI controls interaction:

iPhone:

Handling some process under Touch event during when particular UI control interaction:

Whenever we want to do some process under touch event, we can follow that under
"- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event"

But when we have a UIControl like UILabels, Imagebuttons etc. and we want to do some process when Touch events occurred on that particular UIControls, following the below process to do it.

1. Create a UIControl. For example: UILabel

2. Link UILabel with declaration property in code. Make sure UserInteraction checkbox is enabled for UILabel in I.B

3. Add the below code in your code.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint point = [[touches anyObject] locationInView:urlLabel];
if( [urlLabel hitTest:point withEvent:nil] )
[ [UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.mywebsite.com"] ];
else
[super touchesEnded:touches withEvent:event];
}

What it does is, whenever touch event is happening on the UILabel, it will launch the URL website given.

You got to go ... and be success !!!!!!!

Thank you.

Cheers!
M.P.Prabakar
Senior Systems Analyst