2015-10-12 17 views
11

ho problemi su come implementare PlaybackParams per impostare Velocità Video:Android 6.0 - Impostare la velocità video con PlaybackParams

public PlaybackParams getPlaybackParams()

Aggiunto a livello di API 23
ottiene la velocità di riproduzione utilizzando PlaybackParams.

PlaybackParams setSpeed (float speed) //Sets the speed factor. 

Returns:
la velocità di riproduzione in uso.
Throws IllegalStateException:
se il motore di sincronizzazione interno o la traccia audio non sono stati inizializzati.

Questo è il mio codice:

mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() 
{ 
    @Override 
    public void onPrepared(MediaPlayer mp) 
    { 
     mp.setPlaybackParams(new PlaybackParams().setSpeed(1.f)); 

     if (mPlaybackState == PlaybackState.PLAYING) { mVideoView.start();} 
    } 
}); 
+1

Qual è il problema esattamente? L'impostazione della velocità di '1.f' funziona correttamente (poiché ** 1.0 ** è la velocità normale) o ricevi un messaggio di errore? Prova: 'mp.setPlaybackParams (new PlaybackParams(). SetSpeed ​​(2.5));' Cosa succede ...? –

risposta

3

certi di acquistare un'IllegalStateException mentre chiamando il metodo 'setPlayParams', perché non stai facendo PlaybackParams params = mp.getPlaybackParams(), impostare la velocità e quindi passalo a mp.setPlaybackParams()! Imposta la velocità DIRETTAMENTE mentre chiami mp.getPlayParams()!

MediaPlayer mp = ...; 
float speed = 0.55f;  
mp.setPlaybackParams(mp.getPlaybackParams().setSpeed(speed)); 
2

Dopo molti tentativi, trovo una soluzione.

Esempio come utilizzare VideoView

final VideoView mVideoView = findViewById(R.id.videoView); 
mVideoView.setVideoPath(Environment.getExternalStorageDirectory() + "/bluetooth/test.webm"); //Path of your file video 
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() 
{ 
    @Override 
    public void onPrepared(MediaPlayer mp) 
    { 
     mp.setPlaybackParams(mp.getPlaybackParams().setSpeed(0.55f)); 
     mVideoView.start(); 
    } 
}); 
MediaController media = new MediaController(this); //this is for play and restart play manually 
media.setAnchorView(mVideoView); 
mVideoView.setMediaController(media); 
//mVideoView.start();