如何玩从Amazon S3的视频在Android应用程序? [英] How to play a video from Amazon S3 in Android App?

查看:350
本文介绍了如何玩从Amazon S3的视频在Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 AWS-Android的SDK-1.4.3 /样本/ S3_SimpleDB_SNS_SQS_Demo 来preVIEW存储在Amazon(亚马逊简单存储服务),我的文件。翻翻code,我看到,他们利用这一点,来存取权限的文件:

I use aws-android-sdk-1.4.3/samples/S3_SimpleDB_SNS_SQS_Demo to preview my files stored on Amazon (Amazon Simple Storage Service). Looking through code I saw that they use this, to acces the files:

com.amazonaws.demo.s3.S3.getDataForObject(第130行)

 public static String getDataForObject( String bucketName, String objectName ) {
        return read( getInstance().getObject( bucketName, objectName ).getObjectContent() );
    }


protected static String read( InputStream stream ) {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream( 8196 );
        byte[] buffer = new byte[1024];
        int length = 0;
        while ( ( length = stream.read( buffer ) ) > 0 ) {
            baos.write( buffer, 0, length );
        }

        return baos.toString();
    }
    catch ( Exception exception ) {
        return exception.getMessage();

    }
}

}

嗯,我已经修改了此方法,以返回 ByteArrayOutputStream ,而不是那么我很容易把它转换为字符串位图(将 ByteArrayOutputStream.toByteArray()然后使用 BitmapFactory.de codeByteArray(byte []的数据,诠释抵消,诠释长度,选项选择采用))。

Well, I have modified this methods to return ByteArrayOutputStream instead then I easily transform it to String or Bitmap (applying ByteArrayOutputStream.toByteArray() then using BitmapFactory.decodeByteArray(byte[] data, int offset, int length, Options opts)).

所以,它适用于文本文件和图片。我的问题是,当我尝试访问的视频。所以,我的问题是:

So, it works on text-files and pictures. My problem is when I try to access videos. So, my questions are:

1,使用上面提供的方法,我怎么能得到从 ByteArrayOutputStream 视频( ByteArrayOutputStream.toString()),并在播放一个 VideoView 或使用的MediaPlayer 或办法...?

1.Using the method provided above, how could I get a video from ByteArrayOutputStream (ByteArrayOutputStream.toString()) and play it in a VideoView or using MediaPlayer or an approach... ?

2。有谁知道任何其他解决方案以preVIEW视频这个问题,存储在Amazon? (听说他们的 SDK IOS 他们使用的URL来访问文件...)

2 . Does anybody know any other solution to this problem of preview videos stored on Amazon ? (I heard that on their sdk for IOS they use URLs to access files...)

PS:供应文件的URL并打开它在浏览器中没有任何意义,因为这个URL的诡计后过期

PS: Supplying the file URL and open it in browser does not make sense, because this URLs expire after a wile.

推荐答案

首先,我们要为我们的桶的名称和对象(见 AWS-Android的SDK-1.4.3 /样本/ S3_SimpleDB_SNS_SQS_Demo 的COMPLET指南)我们要打开,然后获取URL我们的目标:

First we have to provide the name of our bucket and the object (see aws-android-sdk-1.4.3/samples/S3_SimpleDB_SNS_SQS_Demo for a complet guide) we want to open then get the URL to our object:

    AWSCredentials myCredentials = new BasicAWSCredentials("YOUR_AMAZON_ACCESS_KEY_ID", "YOUR_AMAZON_SECRET_KEY_ID");
    AmazonS3 s3client = new AmazonS3Client(myCredentials);
    GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, objectName);
    URL objectURL = s3client.generatePresignedUrl(request);

现在,只需播放视频在视频来看,提供的网址获得:

Now, just play the video in a video view, supplying the URL obtained:

    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    mediaCtrl = new MediaController(this);
    mediaCtrl.setMediaPlayer(videoView);
    videoView.setMediaController(mediaCtrl);
    Uri clip = Uri.parse(objectURL.toString());
    videoView.setVideoURI(clip);
    videoView.requestFocus();
    videoView.start();

我要称谢@CommonsWare为

I want to give thanks to @CommonsWare for

  • 说明我通过 REST API (甚至是code我用的是从 AWS-SDK REST API 文件帮我,也表明亚马逊请求对象)的其他方式

  • indicating me through REST API (even the code I used is from aws-sdk reading the REST API documentation helped me and show also other ways of requesting Amazon objects)

说明我使用生成presignedUrl()

在code的<一个href="https://github.com/commonsguy/cw-advandroid/blob/master/Media/Video/src/com/commonsware/android/video/VideoDemo.java"相对=nofollow>播放视频也激发了他的材料的。

这篇关于如何玩从Amazon S3的视频在Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆