在我的手持设备上播放视频
Playing a video on my handled device
我写了一个播放视频的基本代码。该代码适用于我的 phone :
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surface created");
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),"a.wmv");
Log.d(TAG,file.getPath());
mp.setDataSource("/storage/emulated/0/Download/a.wmv");
mp.setOnPreparedListener(MainActivity.this); //Une fois le buffer pret
mp.setOnErrorListener(MainActivity.this); //gestion des erreurs
mp.setDisplay(holder);
mp.prepareAsync(); //Peut prendre du temps (buffering)!
} catch (IOException e) {
Log.e(TAG, "error " + e.getMessage());
e.printStackTrace();
}
}
@Override
public void onPrepared(MediaPlayer mp) {
int videoWidth = mp.getVideoWidth();
int videoHeight = mp.getVideoHeight();
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
android.view.ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams();
//Set the width of the SurfaceView to the width of the screen
lp.width = screenWidth;
lp.height = (int) (((float)videoHeight / (float)videoWidth) * (float)screenWidth);
mSurfaceView.setLayoutParams(lp);
mp.start();
}
当我尝试在我的 android 可穿戴设备上使用它时,出现以下错误:
setDataSourceFD failed.: status=0x80000000
这可能与我的 android 可穿戴设备不支持的编解码器问题有关吗?
可穿戴设备上没有硬件支持的编解码器,因此如果您确实需要玩类似的东西,您将需要编写一个软件解码器,并且由于那里的资源有限,它可能无法正常运行。
我写了一个播放视频的基本代码。该代码适用于我的 phone :
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surface created");
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),"a.wmv");
Log.d(TAG,file.getPath());
mp.setDataSource("/storage/emulated/0/Download/a.wmv");
mp.setOnPreparedListener(MainActivity.this); //Une fois le buffer pret
mp.setOnErrorListener(MainActivity.this); //gestion des erreurs
mp.setDisplay(holder);
mp.prepareAsync(); //Peut prendre du temps (buffering)!
} catch (IOException e) {
Log.e(TAG, "error " + e.getMessage());
e.printStackTrace();
}
}
@Override
public void onPrepared(MediaPlayer mp) {
int videoWidth = mp.getVideoWidth();
int videoHeight = mp.getVideoHeight();
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
android.view.ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams();
//Set the width of the SurfaceView to the width of the screen
lp.width = screenWidth;
lp.height = (int) (((float)videoHeight / (float)videoWidth) * (float)screenWidth);
mSurfaceView.setLayoutParams(lp);
mp.start();
}
当我尝试在我的 android 可穿戴设备上使用它时,出现以下错误:
setDataSourceFD failed.: status=0x80000000
这可能与我的 android 可穿戴设备不支持的编解码器问题有关吗?
可穿戴设备上没有硬件支持的编解码器,因此如果您确实需要玩类似的东西,您将需要编写一个软件解码器,并且由于那里的资源有限,它可能无法正常运行。