如何玩从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 fromaws-sdk
reading theREST API
documentation helped me and show also other ways of requesting Amazon objects)
说明我使用生成presignedUrl()
在code的播放视频也激发了他的材料的。