public class CatagoryVideoPlay extends Activity implements Runnable,MediaPlayer.OnCompletionListener {
ImageView iv;
Button b1;
static ProgressDialog progressDialog;
movieclass mv;
public static int position;
String spath;
VideoView mVideoView;
String s_url;
String f_path;
public Timer timer;
public TimerTask timertask;
MediaController mc;
SurfaceHolder holder;
MediaPlayer mp;
private Throwable t;
private static int IO_BUFFER_SIZE = 512;
Bitmap bitmap = null;
boolean video1;
@Override
public void onCreate(Bundle icicle) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(icicle);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.catagoryvideo);
b1 = (Button) findViewById(R.id.button);
progressDialog = ProgressDialog.show(this, "", "Loading...", true);
mv = (movieclass) MyXMLHandler.v.get(position);
spath = mv.sponsor_path;
s_url = mv.sponsor_url;
f_path = mv.feature_path;
video1=true;
Thread thread = new Thread(this);
try {
Thread.sleep(30);
} catch (InterruptedException ex) {
Logger.getLogger(CatagoryVideoPlay.class.getName()).log(Level.SEVERE, null, ex);
}
thread.start();
}
final void hideImage() {
b1.setVisibility(View.INVISIBLE);
}
final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
progressDialog.dismiss();
if(!video1){
mVideoView = (VideoView) findViewById(R.id.video);
mc = new MediaController(CatagoryVideoPlay.this);
mVideoView.setMediaController(mc);
mc.setAnchorView(mVideoView);
mc.setMediaPlayer(mVideoView);
Uri video = Uri.parse(f_path);
mVideoView.setMediaController(mc);
mVideoView.setVideoURI(video);
mVideoView.requestFocus();
mVideoView.start();
}
int type = Integer.parseInt(mv.sponsor_type);
if (type == 0) {
hideImage();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mVideoView = (VideoView) findViewById(R.id.video);
mc = new MediaController(CatagoryVideoPlay.this);
mVideoView.setMediaController(mc);
mc.setAnchorView(mVideoView);
mc.setMediaPlayer(mVideoView);
Uri video = Uri.parse(spath);
mVideoView.setMediaController(mc);
mVideoView.setVideoURI(video);
mVideoView.requestFocus();
mVideoView.start();
//mVideoView.setOnCompletionListener(this);
} else {
iv = (ImageView) findViewById(R.id.images);
iv.setImageBitmap(getView(spath));
iv.setClickable(true);
timer = new Timer();
timer.schedule(new TimerSchedule(), 30000);
iv.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
timer.cancel();
Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(s_url));
startActivity(browserIntent);
}
});
b1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
b1.setVisibility(View.GONE);
iv.setVisibility(View.GONE);
timer.cancel();
if(video1){
progressDialog = ProgressDialog.show(CatagoryVideoPlay.this, "", "Loading...", true);
try {
Thread.sleep(30);
} catch (InterruptedException ex) {
Logger.getLogger(CatagoryVideoPlay.class.getName()).log(Level.SEVERE, null, ex);
}
video();}
}
});
}
}
};
public void run() {
try {
Thread.sleep(30);
handler.sendEmptyMessage(0);
} catch (InterruptedException ex) {
Logger.getLogger(CatagoryVideoPlay.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Bitmap getView(String url) {
InputStream in = null;
BufferedOutputStream out = null;
try {
in = new BufferedInputStream(new URL(url).openStream(), IO_BUFFER_SIZE);
final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
copy(in, out);
out.flush();
final byte[] data = dataStream.toByteArray();
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
// Message myMessage = new Message(); // myMessage.obj = bitmap; // handler.sendMessage(myMessage); Thread.sleep(15);
} catch (Exception e) {
}
return bitmap;
}
private static void copy(InputStream in, OutputStream out) throws IOException {
byte[] b = new byte[IO_BUFFER_SIZE];
int read;
while ((read = in.read(b)) != -1) {
out.write(b, 0, read);
}
}
public void onCompletion(MediaPlayer arg0) {
video();
}
class TimerSchedule extends TimerTask {
public void run() {
videohandler.sendEmptyMessage(0);
}
}
public void video12() {
mVideoView = (VideoView) findViewById(R.id.video);
mc = new MediaController(CatagoryVideoPlay.this);
mVideoView.setMediaController(mc);
mc.setAnchorView(mVideoView);
mc.setMediaPlayer(mVideoView);
Uri video = Uri.parse(f_path);
mVideoView.setMediaController(mc);
mVideoView.setVideoURI(video);
mVideoView.requestFocus();
progressDialog.dismiss();
mVideoView.start();
} public void video() { try { video1=false; Thread.sleep(30); handler.sendEmptyMessage(0); } catch (InterruptedException ex) { Logger.getLogger(CatagoryVideoPlay.class.getName()).log(Level.SEVERE, null, ex); }
// video12();
}
final Handler videohandler = new Handler() {
@Override
public void handleMessage(Message msg) {
hideImage();
iv.setVisibility(View.GONE);
video();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
};
}
Hi all, I use Above code for Download and set Image And Video Playing(Streaming).. My issue is want to Show Progress Dialog Before Setting Image And Before Starting Video....
PlZ help.. Thanks...