gpt4 book ai didi

Android MediaPlayer 流媒体错误 : 100: MEDIA_ERROR_SERVER_DIED

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:26:52 26 4
gpt4 key购买 nike

我开发了一个应用程序,它利用了 native Android 的 MediaPlayer。我类使用媒体播放器的源代码如下。

问题是只有在某些设备上播放几毫秒后(我只能听到声音,屏幕仍然是黑的)我不断收到 error(100,0),根据 documentation

public static final int MEDIA_ERROR_SERVER_DIED

Media server died. In this case, the application must release the MediaPlayer object and instantiate a new one.

在论坛上,我发现每次获得它时我都需要重置播放器...但是我在很短的时间内获得它然后它就永远消失了。由于播放无用,我无法每秒重置播放器。我不明白为什么有些设备有这个问题而其他设备没有。我知道的是 Android OS > 4.0。

当然,首先调用 init(),然后调用 showVideo()。然后调用代码为 100 的最后一个 onError。使流连续运行而不中断的潜在解决方案是什么?

public class NativePlayer extends Player implements OnBufferingUpdateListener,
OnCompletionListener, OnErrorListener, OnInfoListener {

private VideoView videoview;
private PlayerListener listener;
private MainActivity context;

private final Logger logger = LoggerFactory.getLogger(NativePlayer.class);

@Override
public void init(MainActivity activity) {
this.videoview = (VideoView) activity.findViewById(R.id.video);
context = activity;
}

@Override
public void showVideo(final String url, final PlayerListener _listener) {
listener = _listener;
videoview.setVisibility(View.VISIBLE);
try {
Uri video = Uri.parse(url);
videoview.setVideoURI(video);
} catch (Exception e) {
logger.error("Error playing video", e);
listener.onVideoError();
return;
}

videoview.setOnCompletionListener(this);
videoview.setOnErrorListener(this);
videoview.requestFocus();

videoview.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
videoview.start();
if (listener != null) {
listener.onVideoStarted();
}
}
});
}

@Override
public void onStop() {
stop();
}

private void stop() {
if (videoview == null) {
return;
}
if (videoview.isPlaying()) {
videoview.stopPlayback();
}
}

@Override
public void onDestroy() {
}

@Override
public void onCompletion(MediaPlayer mp) {
stop();
}

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
if (listener != null) {
listener.onVideoError();
}
return false;
}

@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
if (listener != null) {
listener.onInfo(what, extra);
}
return false;
}

@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
if (listener != null) {
listener.onBufferingUpdate(percent);
}
}
}

最佳答案

我遇到了同样的问题(错误 100、媒体播放器死机等)。我通过使用 .stopPlayback() 解决了它,并再次开始播放。下面是我的部分代码:

private void startWatchVideo(final string video_link) {
videoViewVA.setMediaController(new MediaController(this));
videoViewVA.setVideoURI(Uri.parse(video_link));
videoViewVA.requestFocus();
videoViewVA.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer media) {
media.start();
}
});

videoViewVA.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer media, int what, int extra) {
if (what == 100)
{
videoViewVA.stopPlayback();
startWatchVideo(video_link);
}
return true;
}
});
}

在实践中,视频似乎只是变慢了

关于Android MediaPlayer 流媒体错误 : 100: MEDIA_ERROR_SERVER_DIED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19869473/

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