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(); 
}