如何通过Java for Android中的MediaPlayer将MP4从我的S3存储桶流式传输到SurfaceView?
我目前有这个代码并且它没有显示任何视频,它只是黑色,即使URI是正确的:
// GET PROPERTIES OF THE FRAME IN THE XML VIEW's
final SurfaceView surfaceViewFrame = (SurfaceView) llShowDrop.findViewById(R.id.camerapreview);
final SurfaceHolder holder = surfaceViewFrame.getHolder();
holder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
String object_key = this.getString(R.string.video) + "/" + ud.getFileName();
AmazonS3 s3client = new AmazonS3Client(HelperAws.getCredentialsProvider());
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(this.getString(R.string.public_bucket), object_key);
URL objectURL = s3client.generatePresignedUrl(request);
String url = objectURL.toString();
player = new MediaPlayer();
player.setDisplay(holder);
player.setDataSource(this, Uri.parse(url));
player.setScreenOnWhilePlaying(true);
player.setLooping(true);
player.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
mp.stop();
return false;
}
});
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (!mp.isPlaying()) {
player.start();
}
}
});
player.prepare();
} catch (Exception e) {
stopPlayer();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.i(Helpers.TAG, "SURFACE CHANGED");
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.i(Helpers.TAG, "SURFACE DESCTROYED");
}
}
);