- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面是我正在使用的代码。我正在使用一个 vimeo 视频 url,它在我第一次加载 Activity 时工作正常,但在第二次调用 Activity 时出现问题,它显示消息尝试在无效的媒体播放器上调用 getDuration。
public class VideoActivity extends Activity {
public LinearLayout main_Lay;
private TextView textViewPlayed;
private TextView textViewLength;
private SeekBar seekBarProgress;
private SurfaceView surfaceViewFrame;
private ImageView imageViewPauseIndicator;
private MediaPlayer player;
private SurfaceHolder holder;
private ProgressBar progressBarWait;
private Timer updateTimer;
// private Bundle extras;
private Animation hideMediaController;
private LinearLayout linearLayoutMediaController;
private static final String TAG = "androidEx2 = VideoSample";
public boolean isFullScreen = false;
private Context m_context;
public GestureDetector ggg;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.video_layout);
this.m_context = this;
main_Lay = (LinearLayout) findViewById(R.id.main_lay);
main_Lay.startAnimation(AnimationUtils.loadAnimation(this,
R.anim.slide_out_up));
surfaceViewFrame = (SurfaceView) findViewById(R.id.surfaceViewFrame);
final Button button = (Button) findViewById(R.id.full);
ggg = new GestureDetector(new OnGestureListener() {
public boolean onSingleTapUp(MotionEvent arg0) {
// TODO Auto-generated method stub
try {
if (player != null) {
if (player.isPlaying())
player.stop();
player.reset();
player.release();
if (updateTimer != null) {
updateTimer.cancel();
}
finish();
}
} catch (Exception ex) {
ex.printStackTrace();
player.reset();
player.release();
if (updateTimer != null) {
updateTimer.cancel();
}
finish();
}
return true;
}
public void onShowPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
public boolean onScroll(MotionEvent arg0, MotionEvent arg1,
float arg2, float arg3) {
// TODO Auto-generated method stub
return false;
}
public void onLongPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean onFling(MotionEvent arg0, MotionEvent arg1,
float arg2, float arg3) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onDown(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
}
});
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (player != null) {
if (!isFullScreen) {
isFullScreen = true;
button.setBackgroundResource(R.drawable.fullscreen_exit_alt);
// Get the width of the screen
int screenWidth = ((Activity) m_context)
.getWindowManager().getDefaultDisplay()
.getWidth();
int screenHeight = ((Activity) m_context)
.getWindowManager().getDefaultDisplay()
.getHeight();
WidthResizeAnimation zoom_out = new WidthResizeAnimation(
main_Lay, screenWidth, screenHeight, false);
zoom_out.setDuration(600);
zoom_out.setFillAfter(true);
WidthResizeAnimation zoom_outt = new WidthResizeAnimation(
surfaceViewFrame, screenWidth, screenHeight,
false);
zoom_outt.setDuration(600);
zoom_outt.setFillAfter(true);
surfaceViewFrame.startAnimation(zoom_outt);
main_Lay.startAnimation(zoom_out);
} else {
isFullScreen = false;
button.setBackgroundResource(R.drawable.fullscreen_alt);
int videoWidth = player.getVideoWidth();
int videoHeight = player.getVideoHeight();
float videoProportion = (float) videoWidth
/ (float) videoHeight;
Log.i(TAG, "VIDEO SIZES: W: " + videoWidth + " H: "
+ videoHeight + " PROP: " + videoProportion);
// Get the width of the screen
int screenWidth = ((Activity) m_context)
.getWindowManager().getDefaultDisplay()
.getWidth();
int screenHeight = ((Activity) m_context)
.getWindowManager().getDefaultDisplay()
.getHeight();
float screenProportion = (float) screenWidth
/ (float) screenHeight;
Log.i(TAG, "VIDEO SIZES: W: " + screenWidth + " H: "
+ screenHeight + " PROP: " + screenProportion);
// Get the SurfaceView layout
// parameters
android.view.ViewGroup.LayoutParams lp = surfaceViewFrame
.getLayoutParams();
android.view.ViewGroup.LayoutParams mainLayoutParam = main_Lay
.getLayoutParams();
if (videoProportion > screenProportion) {
lp.width = screenWidth;
lp.height = (int) ((float) screenWidth / videoProportion);
lp.width = (lp.width / 100) * 80;
lp.height = (lp.height / 100) * 80;
} else {
lp.width = (int) (videoProportion * (float) screenHeight);
lp.height = screenHeight;
lp.width = (lp.width / 100) * 70;
lp.height = (lp.height / 100) * 70;
}
WidthResizeAnimation zoom_in = new WidthResizeAnimation(
main_Lay, lp.width, lp.height, false);
zoom_in.setDuration(600);
zoom_in.setFillAfter(true);
// zoom_in.start();
WidthResizeAnimation zoom_inn = new WidthResizeAnimation(
surfaceViewFrame, lp.width, lp.height, false);
zoom_inn.setDuration(600);
zoom_inn.setFillAfter(true);
// zoom_in.start();
surfaceViewFrame.startAnimation(zoom_inn);
main_Lay.startAnimation(zoom_in);
}
}
}
});
final Button pause = (Button) findViewById(R.id.pause);
pause.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (player != null) {
if (player.isPlaying()) {
player.pause();
pause.setBackgroundResource(R.drawable.play);
imageViewPauseIndicator.setVisibility(View.GONE);
} else {
pause.setBackgroundResource(R.drawable.pause);
player.start();
imageViewPauseIndicator.setVisibility(View.GONE);
}
}
}
});
linearLayoutMediaController = (LinearLayout) findViewById(R.id.linearLayoutMediaController);
linearLayoutMediaController.setVisibility(View.GONE);
hideMediaController = AnimationUtils.loadAnimation(m_context,
R.anim.disapearing);
hideMediaController.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated
// method stub
linearLayoutMediaController.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated
// method stub
}
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated
// method stub
}
});
imageViewPauseIndicator = (ImageView) findViewById(R.id.imageViewPauseIndicator);
imageViewPauseIndicator.setVisibility(View.GONE);
if (player != null) {
if (!player.isPlaying()) {
imageViewPauseIndicator.setVisibility(View.GONE);
}
}
textViewPlayed = (TextView) findViewById(R.id.textViewPlayed);
textViewLength = (TextView) findViewById(R.id.textViewLength);
surfaceViewFrame.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated
// method stub
if (arg0.getId() == R.id.surfaceViewFrame) {
if (linearLayoutMediaController.getVisibility() == View.GONE) {
linearLayoutMediaController.setVisibility(View.VISIBLE);
hideMediaController();
}
}
}
});
surfaceViewFrame.setClickable(false);
seekBarProgress = (SeekBar) findViewById(R.id.seekBarProgress);
seekBarProgress
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated
// method stub
if (player.isPlaying()) {
progressBarWait.setVisibility(View.VISIBLE);
player.seekTo(arg0.getProgress() * 1000);
Log.i(TAG,
"========== SeekTo : " + arg0.getProgress());
}
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated
// method stub
}
@Override
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
Log.i(TAG, "========== onProgressChanged : " + progress
+ " from user: " + fromUser);
if (!fromUser) {
textViewPlayed
.setText(durationInSecondsToString(progress));
}
}
});
seekBarProgress.setProgress(0);
progressBarWait = (ProgressBar) findViewById(R.id.progressBarWait);
holder = surfaceViewFrame.getHolder();
holder.addCallback(new Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
player.setDisplay(holder);
playVideo();
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
});
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
player = new MediaPlayer();
player.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
// TODO Auto-generated method stub
Log.i(TAG, "========== onPrepared ===========");
try {
int duration = player.getDuration() / 1000; // duration
// in
// seconds
seekBarProgress.setMax(duration);
textViewLength.setText(durationInSecondsToString(duration));
progressBarWait.setVisibility(View.GONE);
// Get the dimensions of the video
int videoWidth = player.getVideoWidth();
int videoHeight = player.getVideoHeight();
float videoProportion = (float) videoWidth
/ (float) videoHeight;
Log.i(TAG, "VIDEO SIZES: W: " + videoWidth + " H: "
+ videoHeight + " PROP: " + videoProportion);
player.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
// Get the width of the screen
int screenWidth = ((Activity) m_context).getWindowManager()
.getDefaultDisplay().getWidth();
int screenHeight = ((Activity) m_context)
.getWindowManager().getDefaultDisplay().getHeight();
float screenProportion = (float) screenWidth
/ (float) screenHeight;
Log.i(TAG, "VIDEO SIZES: W: " + screenWidth + " H: "
+ screenHeight + " PROP: " + screenProportion);
// Get the SurfaceView layout
// parameters
android.view.ViewGroup.LayoutParams lp = surfaceViewFrame
.getLayoutParams();
android.view.ViewGroup.LayoutParams mainLayoutParam = main_Lay
.getLayoutParams();
if (videoProportion > screenProportion) {
lp.width = screenWidth;
lp.height = (int) ((float) screenWidth / videoProportion);
lp.width = (lp.width / 100) * 80;
lp.height = (lp.height / 100) * 80;
} else {
lp.width = (int) (videoProportion * (float) screenHeight);
lp.height = screenHeight;
lp.width = (lp.width / 100) * 90;
lp.height = (lp.height / 100) * 90;
}
// Commit the layout parameters
surfaceViewFrame.setLayoutParams(lp);
RelativeLayout.LayoutParams rr = new RelativeLayout.LayoutParams(
lp.width, lp.height);
rr.addRule(RelativeLayout.CENTER_IN_PARENT);
main_Lay.setLayoutParams(rr);
// Start video
if (!player.isPlaying()) {
player.start();
updateMediaProgress();
linearLayoutMediaController.setVisibility(View.VISIBLE);
hideMediaController();
}
surfaceViewFrame.setClickable(true);
} catch (Exception ex) {
player.release();
finish();
ex.printStackTrace();
}
;
}
});
player.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
if (arg0.isPlaying()) {
arg0.stop();
}
arg0.release();
finish();
Log.e("Lrapp", "Error code" + arg1);
return true;
}
});
player.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer arg0) {
// TODO Auto-generated method stub
arg0.stop();
arg0.release();
if (updateTimer != null) {
updateTimer.cancel();
}
finish();
}
});
player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
@Override
public void onBufferingUpdate(MediaPlayer arg0, int arg1) {
// TODO Auto-generated method stub
int progress = (int) ((float) arg0.getDuration() * ((float) arg1 / (float) 100));
seekBarProgress.setSecondaryProgress(progress / 1000);
}
});
player.setOnSeekCompleteListener(new OnSeekCompleteListener() {
@Override
public void onSeekComplete(MediaPlayer arg0) {
// TODO Auto-generated method stub
progressBarWait.setVisibility(View.GONE);
}
});
player.setScreenOnWhilePlaying(true);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return ggg.onTouchEvent(event);
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
try {
if (player != null) {
if (player.isPlaying())
player.stop();
player.release();
if (updateTimer != null) {
updateTimer.cancel();
}
finish();
}
} catch (Exception ex) {
ex.printStackTrace();
player.release();
if (updateTimer != null) {
updateTimer.cancel();
}
finish();
}
}
private void playVideo() {
new Thread(new Runnable() {
public void run() {
try {
player.setDataSource("video url");
player.prepareAsync();
} catch (IllegalArgumentException e) {
showToast("Error while playing video. Please, check your network connection.");
Log.i(TAG,
"========== IllegalArgumentException ===========");
e.printStackTrace();
if (player.isPlaying())
player.stop();
player.release();
player = null;
if (updateTimer != null) {
updateTimer.cancel();
}
finish();
} catch (IllegalStateException e) {
showToast("Error while playing video. Please, check your network connection.");
Log.i(TAG, "========== IllegalStateException ===========");
e.printStackTrace();
if (player.isPlaying())
player.stop();
player.release();
player = null;
if (updateTimer != null) {
updateTimer.cancel();
}
finish();
} catch (IOException e) {
showToast("Error while playing video. Please, check your network connection.");
Log.i(TAG, "========== IOException ===========");
e.printStackTrace();
if (player.isPlaying())
player.stop();
player.release();
player = null;
if (updateTimer != null) {
updateTimer.cancel();
}
finish();
}
}
}).start();
}
private void showToast(final String string) {
((Activity) m_context).runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(m_context, string, Toast.LENGTH_LONG).show();
;
}
});
}
private void hideMediaController() {
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(5000);
((Activity) m_context).runOnUiThread(new Runnable() {
public void run() {
linearLayoutMediaController
.startAnimation(hideMediaController);
}
});
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
private void updateMediaProgress() {
updateTimer = new Timer("progress Updater");
updateTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
((Activity) m_context).runOnUiThread(new Runnable() {
public void run() {
try {
seekBarProgress.setProgress(player
.getCurrentPosition() / 1000);
} catch (Exception ex) {
ex.printStackTrace();
player.release();
}
}
});
}
}, 0, 1000);
}
public static String durationInSecondsToString(int sec) {
int hours = sec / 3600;
int minutes = (sec / 60) - (hours * 60);
int seconds = sec - (hours * 3600) - (minutes * 60);
String formatted = String.format("%d:%02d:%02d", hours, minutes,
seconds);
return formatted;
}
}
最佳答案
第二次打开 Activity 后,表面回调被调用 -> playVideo()
-> 播放器未正确初始化。解决方案可能是:
将其插入到 playVideo()
方法中:
if (player != null)
{
player.reset();
} else
{
player = new MediaPlayer();
}
//init
关于android - getDuration 正在抛出尝试调用无效的媒体播放器第二次调用媒体播放器时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17894871/
为了让我的代码几乎完全用 Jquery 编写,我想用 Jquery 重写 AJAX 调用。 这是从网页到 Tomcat servlet 的调用。 我目前情况的类似代码: var http = new
我想使用 JNI 从 Java 调用 C 函数。在 C 函数中,我想创建一个 JVM 并调用一些 Java 对象。当我尝试创建 JVM 时,JNI_CreateJavaVM 返回 -1。 所以,我想知
环顾四周,我发现从 HTML 调用 Javascript 函数的最佳方法是将函数本身放在 HTML 中,而不是外部 Javascript 文件。所以我一直在网上四处寻找,找到了一些简短的教程,我可以根
我有这个组件: import {Component} from 'angular2/core'; import {UserServices} from '../services/UserService
我正在尝试用 C 实现一个简单的 OpenSSL 客户端/服务器模型,并且对 BIO_* 调用的使用感到好奇,与原始 SSL_* 调用相比,它允许一些不错的功能。 我对此比较陌生,所以我可能会完全错误
我正在处理有关异步调用的难题: 一个 JQuery 函数在用户点击时执行,然后调用一个 php 文件来检查用户输入是否与数据库中已有的信息重叠。如果是这样,则应提示用户确认是否要继续或取消,如果他单击
我有以下类(class)。 public Task { public static Task getInstance(String taskName) { return new
嘿,我正在构建一个小游戏,我正在通过制作一个数字 vector 来创建关卡,该数字 vector 通过枚举与 1-4 种颜色相关联。问题是循环(在 Simon::loadChallenge 中)我将颜
我有一个java spring boot api(数据接收器),客户端调用它来保存一些数据。一旦我完成了数据的持久化,我想进行另一个 api 调用(应该处理持久化的数据 - 数据聚合器),它应该自行异
首先,这涉及桌面应用程序而不是 ASP .Net 应用程序。 我已经为我的项目添加了一个 Web 引用,并构建了各种数据对象,例如 PayerInfo、Address 和 CreditCard。但问题
我如何告诉 FAKE 编译 .fs文件使用 fsc ? 解释如何传递参数的奖励积分,如 -a和 -target:dll . 编辑:我应该澄清一下,我正在尝试在没有 MSBuild/xbuild/.sl
我使用下划线模板配置了一个简单的主干模型和 View 。两个单独的 API 使用完全相同的配置。 API 1 按预期工作。 要重现该问题,请注释掉 API 1 的 URL,并取消注释 API 2 的
我不确定什么是更好的做法或更现实的做法。我希望从头开始创建目录系统,但不确定最佳方法是什么。 我想我在需要显示信息时使用对象,例如 info.php?id=100。有这样的代码用于显示 Game.cl
from datetime import timedelta class A: def __abs__(self): return -self class B1(A):
我在操作此生命游戏示例代码中的数组时遇到问题。 情况: “生命游戏”是约翰·康威发明的一种细胞自动化技术。它由一个细胞网格组成,这些细胞可以根据数学规则生存/死亡/繁殖。该网格中的活细胞和死细胞通过
如果我像这样调用 read() 来读取文件: unsigned char buf[512]; memset(buf, 0, sizeof(unsigned char) * 512); int fd;
我用 C 编写了一个简单的服务器,并希望调用它的功能与调用其他 C 守护程序的功能相同(例如使用 ./ftpd start 调用它并使用 ./ftpd stop 关闭该实例)。显然我遇到的问题是我不知
在 dos 中,当我粘贴此命令时它会起作用: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://google.
在 dos 中,当我粘贴此命令时它会起作用: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://google.
我希望能够从 cmd 在我的 Windows 10 计算机上调用 python3。 我已重新安装 Python3.7 以确保选择“添加到路径”选项,但仍无法调用 python3 并使 CMD 启动 P
我是一名优秀的程序员,十分优秀!