我的代码运行完美然后我在我的项目中编写了另一个类,回去尝试完全相同的代码并开始出错。
这是我的代码:
public class myMediaPlayer extends Activity implements TextureView.SurfaceTextureListener,
MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnCompletionListener,
MediaPlayer.OnPreparedListener, MediaPlayer.OnVideoSizeChangedListener{
private TextureView mTextureView;
private MediaPlayer mMediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_channel_player);
mTextureView = (TextureView)findViewById(R.id.Video);
mTextureView.setSurfaceTextureListener(this);
Log.d("debug","Listener Set");
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Surface s = new Surface(surface);
Log.d("debug", "Surface Texture Available");
try {
mMediaPlayer = new MediaPlayer();
try {
mMediaPlayer.setDataSource(this, Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.t));
} catch (IOException e) {
Log.d("IOException", "setDataSource method faulty");
}
Log.d("debug", "data source set");
mMediaPlayer.setSurface(s);
Log.d("debug", "Surface set");
try {
mMediaPlayer.prepare();
} catch (IOException e) {
Log.d("IOException", "Prepare method problem");
}
Log.d("debug", "prepared");
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
Log.d("debug", "listeners set");
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("error", e.getMessage());
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("error", e.getMessage());
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("error", e.getMessage());
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
//TODO
Log.d("Debug","SurfaceTextureSizeChanged");
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
Log.d("Debug","SurfaceTextureDestroyed");
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
//TODO
Log.d("Debug","SurfaceTextureUpdated");
}
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.d("Debug","BufferingUpdate");
}
@Override
public void onCompletion(MediaPlayer mp) {
Log.d("Debug", "Media Player Complete");
}
@Override
public void onPrepared(MediaPlayer mp) {
Log.d("Debug","Media Player Prepared");
mp.start();
}
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
Log.d("Debug","VideoSizeChanged");
}
@Override
public void onDestroy() {
Log.d("Debug","Activity Destroyed");
if (mMediaPlayer != null) mMediaPlayer.release();
}
}
这与演示完全相同。它工作了一段时间,但突然出现了prepare方法的错误(我在日志中得到“prepare method error”)。任何人都知道它为什么突然停止工作?
这是LogCat输出:
01-12 20:18:10.530 23003-23003 / com.edifyelectronics.tv.app W / ActivityThread:应用程序com.edifyelectronics.tv.app可以 在端口8100 ... 01-12 20:18:10.559上调试 23003-23003 / com.edifyelectronics.tv.app D / debug:Listener Set 01-12 20:18:10.570 23003-23023 / com.edifyelectronics.tv.app D / OpenGLRenderer:渲染请求的脏区:true 01-12 20:18:10.579 23003-23003 / com.edifyelectronics.tv.app D / Atlas: 验证地图... 01-12 20:18:10.608 23003-23023 / com.edifyelectronics.tv.app I / Adreno-EGL: :QUALCOMM Build:2014年10月28日,c33033c, Ia6306ec328 01-12 20:18:10.609 23003-23023 / com.edifyelectronics.tv.app I / OpenGLRenderer:已初始化 EGL,版本1.4 01-12 20:18:10.637 23003-23023 / com.edifyelectronics.tv.app D / OpenGLRenderer:启用 调试模式0 01-12 20:18:10.742 23003-23003 / com.edifyelectronics.tv.app D / debug:表面纹理 可用01-12 20:18:11.080 23003-23003 / com.edifyelectronics.tv.app D / debug:数据源集01-12 20:18:11.082 23003-23003 / com.edifyelectronics.tv.app D / debug:曲面组01-12 20:18:11.176 23003-23021 / com.edifyelectronics.tv.app E / MediaPlayer: 错误(1,-2147483648)01-12 20:18:11.177 23003-23003 / com.edifyelectronics.tv.app D / IOException:准备方法 问题01-12 20:18:11.177 23003-23003 / com.edifyelectronics.tv.app D / debug:准备01-12 20:18:11.177 23003-23003 / com.edifyelectronics.tv.app D / debug:listeners set
答案 0 :(得分:0)
不是答案或解决方案,但没有做任何事情,它只是突然重新开始工作。