gpt4 book ai didi

android - 我在 android 中使用 VideoView : MediaPlayer(29449): Error (1, -1004 时得到的这个错误是什么

转载 作者:行者123 更新时间:2023-11-30 03:38:58 26 4
gpt4 key购买 nike

我想使用 VideoView 播放直播,但我得到的错误是什么:

04-21 21:13:27.326: D/MediaPlayer(29449): Couldn't open file on client side, trying server side
04-21 21:13:27.529: D/dalvikvm(29449): GC_CONCURRENT freed 81K, 2% free 9218K/9328K, paused 5ms+3ms, total 28ms
04-21 21:14:17.654: E/MediaPlayer(29449): error (1, -1004)
04-21 21:14:17.654: E/MediaPlayer(29449): Error (1,-1004)
04-21 21:14:17.654: D/VideoView(29449): Error: 1,-1004

我播放直播的代码:

public  class VideoStreamingActivity  extends Activity implements OnPreparedListener,OnErrorListener{

private Vibrator vibrator;
private boolean readyToPlay;
private ProgressBar progress;
private ProgressDialog loading;
private TextView mediaTimeElapsed;
private TextView mediaTime;
private TextView mediaInfo;
private Button play;
private Button stop;
private String url;
private VideoView vvStreaming;
private CountDownTimer timer;

/** Called when the activity is first created.*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_video_streaming);

//variables init
vvStreaming = (VideoView)findViewById(R.id.vvStreaming);



url ="http://www.ted.com/talks/download/video/8584/talk/761";
play = (Button)findViewById(R.id.btnPlay);
stop = (Button)findViewById(R.id.btnPause);

mediaInfo = (TextView) findViewById(R.id.tvMediaInfo);
mediaTime = (TextView)findViewById(R.id.tvTime);
mediaTimeElapsed = (TextView)findViewById(R.id.tvTimeElapsed);

progress = (ProgressBar) findViewById(R.id.progressBar1);
loading = new ProgressDialog(this);
loading.setMessage("Loading...");

vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);

//flag indicating that content is ready for playback
readyToPlay = false;

// listeners for VideoView:

//vvStreaming.setOnPreparedListener(this);
//vvStreaming.setOnErrorListener(this);

vvStreaming.setVideoURI(Uri.parse(url));
vvStreaming.setMediaController(new MediaController(this));
vvStreaming.start();



}

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
loading.hide();
return false;
}

@Override
public void onPrepared(MediaPlayer mp) {
Log.d(this.getClass().getName(), "prepared");
mp.setLooping(true);
loading.hide();



//onVideoSizeChangedListener declaration
/* mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
if(width!=0 && height!=0) {
Log.d(this.getClass().getName(), "logo off");
logo.setVisibility(ImageView.INVISIBLE);
} else {
Log.d(this.getClass().getName(), "logo on");
logo.setVisibility(ImageView.VISIBLE);
}
}
});*/


//onBufferingUpdateListener declaration
mp.setOnBufferingUpdateListener(new OnBufferingUpdateListener()
{
// show updated information about the buffering progress
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.d(this.getClass().getName(), "percent: " + percent);
progress.setSecondaryProgress(percent);
}
});

//onSeekCompletionListener declaration
mp.setOnSeekCompleteListener(new OnSeekCompleteListener() {

//show current frame after changing the playback position
@Override
public void onSeekComplete(MediaPlayer mp) {
if(mp.isPlaying()) {
// playMedia(null);
// playMedia(play);
} else {
// playMedia(null);
// playMedia(play);
// playMedia(null);
}
// mediaTimeElapsed.setText(countTime(vvStreaming.getCurrentPosition()));
}
});

mp.setOnCompletionListener(null);

readyToPlay = true;
int time = vvStreaming.getDuration();
int time_elapsed = vvStreaming.getCurrentPosition();
progress.setProgress(time_elapsed);

timer = new CountDownTimer(time, 500) {

@Override
public void onTick(long millisUntilFinished) {
// mediaTimeElapsed.setText(countTime(vvStreaming.getCurrentPosition()));
float a = vvStreaming.getCurrentPosition();
float b = vvStreaming.getDuration();
progress.setProgress((int)(a/b*100));
}

@Override
public void onFinish() {
// stopMedia(null);

}
};
//onTouchListener declaration
progress.setOnTouchListener(new OnTouchListener() {

// enables changing of the current playback position
@Override
public boolean onTouch(View v, MotionEvent event) {
ProgressBar pb = (ProgressBar) v;

int newPosition = (int) (100 * event.getX() / pb.getWidth());
if (newPosition > pb.getSecondaryProgress()) {
newPosition = pb.getSecondaryProgress();
}

switch (event.getAction()) {
// update position when finger is DOWN/MOVED/UP
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
pb.setProgress(newPosition);
vvStreaming.seekTo((int) newPosition * vvStreaming.getDuration() / 100);
break;
}
return true;
}
});
}
}

最佳答案

检查您的 list 用户权限:

<uses-permission android:name="android.permission.INTERNET" />

关于android - 我在 android 中使用 VideoView : MediaPlayer(29449): Error (1, -1004 时得到的这个错误是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16134598/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com