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 (line 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();
}
}
}
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.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 . 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: Supplying the file URL and open it in browser does not make sense, because this URLs expire after a wile.