28 May

Android – Streaming Youtube

@Override
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); setContentView(R.layout.main); 
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=...")));
}

public void onPrepared(MediaPlayer mp) { 
    // TODO Auto-generated method stub
}

28 May

Android – Video Player

public void videoPlayer(String path, String fileName, boolean autoplay){
    //get current window information, and set format, set it up differently, if you need some special effects
    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    //the VideoView will hold the video
    VideoView videoHolder = new VideoView(this);
    //MediaController is the ui control howering above the video (just like in the default youtube player).
    videoHolder.setMediaController(new MediaController(this));
    //assing a video file to the video holder
    videoHolder.setVideoURI(Uri.parse(path+"/"+fileName));
    //get focus, before playing the video.
    videoHolder.requestFocus();
    if(autoplay){
        videoHolder.start();
    }
 
 }

28 May

Android – Audio Recorder

Kita dapat membuat recorder di dalam Android dengan cara:

Pertama tambahkan Permission

<uses-permission android:name="android.permission.RECORD_AUDIO“ />

Kedua, buat objek media recorder

final MediaRecorder recorder = new MediaRecorder();

Ketiga, Method start record

public void start() throws IOException { 
	String state = android.os.Environment.getExternalStorageState(); if(!state.equals(android.os.Environment.MEDIA_MOUNTED)) { 
		throw new IOException("SD Card is not mounted. It is " + state + "."); 
	} 
	
     File directory = new File(path).getParentFile(); 
	if (!directory.exists() && !directory.mkdirs()) { 
		throw new IOException("Path to file could not be created."); 
	} 
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path); 
	recorder.prepare(); 
	recorder.start(); 
}

Keempat, Method stop record

public void stop() throws IOException { 
	recorder.stop(); 
	recorder.release(); 
}

18 May

Android CheckBox Selection Control

CheckBox chk=(CheckBox)findViewById(R.id.Chk);
chk.setOnCheckedChangeListener(new OnCheckedChangeListener() {

  public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
      TextView txt=(TextView)findViewById(R.id.txt);
      if (arg1)
        txt.setText("checked");
      else
        txt.setText("Unchecked");    
      }         
   }
);

07 May

Android Repaint or Redraw

Usually we create custom view with extends “View” class.
But how can we redraw or repaint it?

Kadang kita membuat custom view dengan melakukan extends kelas “View”
Tapi bagaimana cara untuk melakukan redraw atau repaint?

Answer:
call method invalidate() will call draw() method in the class

Jawaban:
panggil method invalidate() maka akan terpanggil kembali fungsi draw() di dalam kelas turunan