Android流AWS S3 MP4到SurfaceView

时间:2015-12-23 05:43:26

标签: java android amazon-web-services amazon-s3 video-streaming

如何通过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"); 
       }
   }

);

0 个答案:

没有答案