将视频转换为 GIF
Converting a video to a GIF
我正在尝试让我的应用程序接受来自 phone 库的视频,以便将其上传并转换为 GIF 格式。我的代码虽然给出了这个构建错误:-
error: <anonymous com.example.bim.Video2gif> is not abstract and does not override abstract method onReschedule(String,ErrorInfo) in UploadCallback
还有关于我的 onActivityResult 方法的警告:-
Overriding method should call super.onActivityResult
代码如下:-
public class Video2gif extends AppCompatActivity {
private Button uploadBtn;
private ProgressBar progressBar;
private int SELECT_VIDEO = 2;
private ImageView img1;
private DownloadManager downloadManager;
private Button download_btn;
private String gifUrl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video2gif);
MediaManager.init(this);
progressBar = findViewById(R.id.progress_bar);
MediaManager.init(this);
img1 = findViewById(R.id.img1);
uploadBtn = findViewById(R.id.uploadBtn);
uploadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pickVideoFromGallery();
}
private void pickVideoFromGallery() {
Intent GalleryIntent = new Intent();
GalleryIntent.setType("video/*");
GalleryIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(GalleryIntent,
"select video"), SELECT_VIDEO);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
if (requestCode == SELECT_VIDEO && resultCode == RESULT_OK) {
Uri selectedVideo = data.getData();
MediaManager.get()
.upload(selectedVideo)
.unsigned("myid")
.option("resource_type", "video")
.callback(new UploadCallback(){
@Override
public void onStart(String requestId) {
progressBar.setVisibility(View.VISIBLE);
Toast.makeText(Video2gif.this,
"Upload Started...", Toast.LENGTH_SHORT).show();
}
public void onProgress() {
}
public void onSuccess(String requestId, Map resultData) {
Toast.makeText(Video2gif.this, "Uploaded Succesfully",
Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
uploadBtn.setVisibility(View.INVISIBLE);
String publicId = resultData.get("public_id").toString();
gifUrl = MediaManager.get().url().resourceType("video")
.transformation(new Transformation().videoSampling("25")
.delay("200").height(200).effect("loop:10").crop("scale"))
.resourceType("video").generate(publicId+".gif");
Glide.with(getApplicationContext()).asGif().load(gifUrl).into(img1);
download_btn.setVisibility(View.VISIBLE);
}
public void onError(String requestId, ErrorInfo error) {
Toast.makeText(Video2gif.this,
"Upload Error", Toast.LENGTH_SHORT).show();
Log.v("ERROR!!", error.getDescription());
}
});
}
}
}
我也在使用 Cloudinary 来帮助将视频处理为 GIF。任何帮助将不胜感激,非常感谢!
当您在 android 中使用接口时,您需要在 activity/fragment 中包含(覆盖)它们包含的回调方法。此外,重写某些系统方法需要您调用它们的 super,这意味着许多活动在相互继承时可能会监听相同的回调。通过在这些回调中添加 super,您可以让结果遍历所有回调。因此,在 OnActivityResult
的情况下,只需在您的方法中添加以下行:
super.onActivityResult(requestCode, resultCode, data);
对于 onReschedule
,您可以让 Android Studio 为您生成。只需转到 Code->Generate-Override Methods 和 select onReschedule
我正在尝试让我的应用程序接受来自 phone 库的视频,以便将其上传并转换为 GIF 格式。我的代码虽然给出了这个构建错误:-
error: <anonymous com.example.bim.Video2gif> is not abstract and does not override abstract method onReschedule(String,ErrorInfo) in UploadCallback
还有关于我的 onActivityResult 方法的警告:-
Overriding method should call super.onActivityResult
代码如下:-
public class Video2gif extends AppCompatActivity {
private Button uploadBtn;
private ProgressBar progressBar;
private int SELECT_VIDEO = 2;
private ImageView img1;
private DownloadManager downloadManager;
private Button download_btn;
private String gifUrl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video2gif);
MediaManager.init(this);
progressBar = findViewById(R.id.progress_bar);
MediaManager.init(this);
img1 = findViewById(R.id.img1);
uploadBtn = findViewById(R.id.uploadBtn);
uploadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pickVideoFromGallery();
}
private void pickVideoFromGallery() {
Intent GalleryIntent = new Intent();
GalleryIntent.setType("video/*");
GalleryIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(GalleryIntent,
"select video"), SELECT_VIDEO);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
if (requestCode == SELECT_VIDEO && resultCode == RESULT_OK) {
Uri selectedVideo = data.getData();
MediaManager.get()
.upload(selectedVideo)
.unsigned("myid")
.option("resource_type", "video")
.callback(new UploadCallback(){
@Override
public void onStart(String requestId) {
progressBar.setVisibility(View.VISIBLE);
Toast.makeText(Video2gif.this,
"Upload Started...", Toast.LENGTH_SHORT).show();
}
public void onProgress() {
}
public void onSuccess(String requestId, Map resultData) {
Toast.makeText(Video2gif.this, "Uploaded Succesfully",
Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
uploadBtn.setVisibility(View.INVISIBLE);
String publicId = resultData.get("public_id").toString();
gifUrl = MediaManager.get().url().resourceType("video")
.transformation(new Transformation().videoSampling("25")
.delay("200").height(200).effect("loop:10").crop("scale"))
.resourceType("video").generate(publicId+".gif");
Glide.with(getApplicationContext()).asGif().load(gifUrl).into(img1);
download_btn.setVisibility(View.VISIBLE);
}
public void onError(String requestId, ErrorInfo error) {
Toast.makeText(Video2gif.this,
"Upload Error", Toast.LENGTH_SHORT).show();
Log.v("ERROR!!", error.getDescription());
}
});
}
}
}
我也在使用 Cloudinary 来帮助将视频处理为 GIF。任何帮助将不胜感激,非常感谢!
当您在 android 中使用接口时,您需要在 activity/fragment 中包含(覆盖)它们包含的回调方法。此外,重写某些系统方法需要您调用它们的 super,这意味着许多活动在相互继承时可能会监听相同的回调。通过在这些回调中添加 super,您可以让结果遍历所有回调。因此,在 OnActivityResult
的情况下,只需在您的方法中添加以下行:
super.onActivityResult(requestCode, resultCode, data);
对于 onReschedule
,您可以让 Android Studio 为您生成。只需转到 Code->Generate-Override Methods 和 select onReschedule