올해는 머신러닝이다.
안드로이드 이러닝 관련 참고 소스 본문
package org.apache.android.media;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.URLUtil;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.widget.VideoView;
public class VideoViewDemo extends Activity {
private static final String TAG = "VideoViewDemo";
private VideoView mVideoView;
private EditText mPath;
private EditText m_currnt;
private ImageButton mPlay;
private ImageButton mPause;
private ImageButton mReset;
private ImageButton mStop;
private String current;
private int current_p;
//쓰레드와바
ProgressBar bar;
Handler handler=new Handler() {
@Override
public void handleMessage(android.os.Message msg) {
//상태바진행
bar.incrementProgressBy(1);
//동영상현재포지션구함
setCurrentPosition();
}
};
boolean isRunning=false;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mVideoView = (VideoView) findViewById(R.id.surface_view);
bar = (ProgressBar)(ProgressBar) findViewById(R.id.progress);
//경로 넣음
mPath = (EditText) findViewById(R.id.path);
mPath.setText("http://daily3gp.com/vids/747.3gp");
//mPath.setText("http://rtsp2.youtube.com/CjcLENy73wIaLgmVcsAQigQC-xMYDSANFEITVUdlbnQtWW91VHViZURlbW8tMUgGUgZ2aWRlb3MM/0/0/0/video.3gp");
//rtsp://rtsp2.youtube.com/CjcLENy73wIaLgmVcsAQigQC-xMYDSANFEITVUdlbnQtWW91VHViZURlbW8tMUgGUgZ2aWRlb3MM/0/0/0/video.3gp
//진행시간표시
m_currnt = (EditText) findViewById(R.id.current_p);
//current_p=mVideoView.getCurrentPosition();
//문자를 넣어야 한다(테스트용)
m_currnt.setText("11");
mPlay = (ImageButton) findViewById(R.id.play);
mPause = (ImageButton) findViewById(R.id.pause);
mReset = (ImageButton) findViewById(R.id.reset);
mStop = (ImageButton) findViewById(R.id.stop);
mPlay.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
playVideo();
}
});
mPause.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (mVideoView != null) {
mVideoView.pause();
//쓰레드임시중지
pStop();
}
}
});
mReset.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (mVideoView != null) {
mVideoView.seekTo(0);
}
}
});
mStop.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (mVideoView != null) {
current = null;
mVideoView.stopPlayback();
//쓰레드중지
onStop();
}
}
});
runOnUiThread(new Runnable(){
public void run() {
playVideo();
}
});
super.onStart();
bar.setProgress(0);
Thread background=new Thread(new Runnable() {
public void run() {
try {
while(isRunning)
{
Thread.sleep(1000);
//함수를 초당주기적으로 호출함
handler.sendMessage(handler.obtainMessage());
}
}
catch (Throwable t) {
// just end the background thread
}
}
});
isRunning=true;
//쓰레드시작
background.start();
}
//쓰레드임시중지
public void pStop() {
isRunning=false;
}
//쓰레드다시가동
public void sStop() {
isRunning=true;
}
//쓰레드완전중지
public void onStop() {
super.onStop();
isRunning=false;
}
protected void setCurrentPosition() {
//현재의 포지션을 변수에 저장
current_p=mVideoView.getCurrentPosition();
current_p=current_p/1000;
//텍스트박스에 넣으려면 형변환
m_currnt.setText(Integer.toString(current_p));
}
//동영상동작
private void playVideo() {
try {
final String path = mPath.getText().toString();
Log.v(TAG, "path: " + path);
if (path == null || path.length() == 0) {
Toast.makeText(VideoViewDemo.this, "주소가명확하지않습니다",
Toast.LENGTH_LONG).show();
} else {
// If the path has not changed, just start the media player
if (path.equals(current) && mVideoView != null) {
mVideoView.start();
mVideoView.requestFocus();
return;
}
//current = path;
//mVideoView.setVideoPath(getDataSource(path));
mVideoView.setVideoPath(path);
mVideoView.start();
mVideoView.requestFocus();
}
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
if (mVideoView != null) {
mVideoView.stopPlayback();
}
}
}
}
'Android > Tip&Tech' 카테고리의 다른 글
VideoView 전체화면으로 보기 팁 (0) | 2011.07.29 |
---|---|
youtube rtsp 구하는 법 (0) | 2011.07.24 |
[펌][Android] 많은 버튼의 클릭이벤트 처리 : button onClick() : OnClickListener (1) | 2011.07.23 |
안드로이드 주소록에서 보여지는 퀵액션 같은 걸 붙여보자 (1) | 2011.07.21 |
epub reader source for android or java (0) | 2011.07.20 |