我正在开发一个Android应用程序,它可以互换地显示视频和图像。该应用程序正在运行,只是它在转换之间显示了一个momemtary空白屏幕。我希望过渡顺利。任何帮助表示赞赏。提前致谢。这是代码 -
public class Standee implements Runnable, OnCompletionListener {
private Vector<File> files;
private Vector<String> timings;
private Handler h;
private VideoView video;
private ImageView image;
private Context ctx;
private int i;
private MediaPlayer player;
public MediaPlayer getMediaPlayer(){
return player;
}
public Standee(Context ctx, VideoView video, ImageView image) {
this.video=video;
this.image=image;
this.ctx=ctx;
i=0;
h=new Handler();
files=new Vector<File>();
timings=new Vector<String>();
player=MediaPlayer.create(ctx, R.raw.background);
try {
FileReader fr=new FileReader(ConfigLoader.BETA_PATH+"media.tmr");
BufferedReader br=new BufferedReader(fr);
String s;
while((s=br.readLine())!=null){
String[] data=s.split(";");
files.add(new File(ConfigLoader.BETA_PATH+data[0]));
timings.add(data[1]);
}
br.close();
video.setOnCompletionListener(this);
video.setMediaController(null);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onCompletion(MediaPlayer arg0) {
}
@Override
public void run() {
if(files.elementAt(i).getAbsolutePath().endsWith(".jpg")){
video.setVisibility(View.GONE);
image.setVisibility(View.VISIBLE);
if(video.isPlaying()){
video.stopPlayback();
}
player=MediaPlayer.create(ctx, R.raw.background);
try {
// player.prepare();
player.setLooping(true);
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
player.start();
showPhoto();
}else if(files.elementAt(i).getAbsolutePath().endsWith(".mp4")){
if(player.isPlaying()){
player.stop();
// player.release();
}
image.setVisibility(View.GONE);
video.setVisibility(View.VISIBLE);
playVideo();
}
h.postDelayed(this, Integer.parseInt(timings.elementAt(i)));
i++;
if (i >= files.size())
i = 0;
}
public void start(){
h.post(this);
}
public void playVideo(){
Uri uri = Uri.parse(files.get(i).getAbsolutePath());
video.setVideoURI(uri);
video.requestFocus();
video.start();
}
public void showPhoto(){
image.setImageBitmap(BitmapFactory.decodeFile(files.elementAt(i)
.getAbsolutePath()));
}
}
答案 0 :(得分:0)
你现在正在做的是让一件事消失,然后再出现另一件事。你可能想看一下android动画系统,试着去寻找更平滑的东西。例如,您可以对视图的alpha属性进行动画处理,以使淡入淡出。 您可以查看http://developer.android.com/training/animation/crossfade.html,这可能会有所帮助。