我试图从Android Uri到字节数组.
我有以下代码,但它一直告诉我字节数组长61个字节,即使文件非常大 - 所以我认为它可能将Uri 字符串转换为字节数组,而不是文件:(
Log.d(LOG_TAG, "fileUriString = " + fileUriString);
Uri tempuri = Uri.parse(fileUriString);
InputStream is = cR.openInputStream(tempuri);
String str=is.toString();
byte[] b3=str.getBytes();
Log.d(LOG_TAG, "len of data is " + imageByteArray.length
+ " bytes");
Run Code Online (Sandbox Code Playgroud)
请有人帮我弄清楚该怎么办?
输出为"fileUriString = content:// media/external/video/media/53","len of data为61字节".
谢谢!
问题:
我的视频没有上传到Facebook.
问题:
如何将视频上传到Facebook?
注意:
我可以从我的画廊上传一张照片.
没有Exceptions被抛出.我认为这个问题存在问题
params.putString("filename", <selectedviedoPath> )
AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(mFacebook);
Bundle params = new Bundle();
//convert to byte stream
**FileInputStream is = new FileInputStream(new File(selectedviedoPath));**
ByteArrayOutputStream bs = new ByteArrayOutputStream();
int data = 0;
while((data = is.read()) != -1)
bs.write(data);
is.close();
byte[] raw = bs.toByteArray();
bs.close();
params.putByteArray("video", raw);
params.putString("filename", <selectedviedoPath> );
mAsyncFbRunner.request("me/videos", params, "POST", new WallPostListener());
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码将视频上传到Facebook
public void uploadVideosFacebook(String videoPath)
{
byte[] data = null;
String dataMsg = "Your video description here.";
String dataName="Mobile.wmv";
Bundle param;
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(API);
InputStream is = null;
try {
is = new FileInputStream(videoPath);
data = readBytes(is);
param = new Bundle();
param.putString("message", dataMsg);
param.putString("filename", dataName);
param.putByteArray("video", data);
mAsyncRunner.request("me/videos", param, "POST", new fbRequestListener(), null);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public byte[] readBytes(InputStream inputStream) throws IOException {
// this dynamically extends …Run Code Online (Sandbox Code Playgroud) 我想通过我的Android应用在Facebook上分享视频.
我通过我的应用程序发布了一个墙,它工作正常.现在我想在Facebook上分享一个视频.所以我尝试下面的代码.
Facebook facebook;
String FB_APP_ID=APP_ID;
byte[] data = null;
Uri uri=Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"filename.mp4"));
String dataPath = uri.getPath();
String dataMsg = "Testing video sharing from my app";
Bundle param;
facebook = new Facebook(FB_APP_ID);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
InputStream is = null;
try {
is = new FileInputStream(dataPath);
data = readBytes(is);
param = new Bundle();
param.putString("message", dataMsg);
param.putByteArray("video", data);
mAsyncRunner.request("me/videos", param, "POST", new SampleUploadListener(), null);
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
} …Run Code Online (Sandbox Code Playgroud)