2015-09-04 76 views
0

我寫了一個基本代碼來播放視頻。該代碼正在我的手機上:在我處理的設備上播放視頻

@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可穿戴?

+0

[MediaPlayer.setDataSource可能導致IOException對於有效文件]重複(http://stackoverflow.com/questions/9657280/mediaplayer-setdatasource-causes-ioexception-for-valid-file) –

回答

0

可穿戴設備上沒有硬件支持的編解碼器,所以如果您確實需要播放類似的內容,您需要編寫一個軟件解碼器,由於資源有限,可能無法正常運行。

相關問題