我正在尝试使用cordova社交分享插件在社交网站上分享视频。到目前为止,我所取得的成就是,我使用以下代码成功捕获了视频 -
var options = {
limit: 1,
duration: 15
};
$cordovaCapture.captureVideo(options).then(function (videoData) {
$scope.videoUrl = videoData[0].fullPath;
}, function (err) {
// An error occurred. Show a message to the user
//alert("video error : "+err);
});
我可以成功找到捕获的视频文件网址,但不幸的是我无法将它们分享到社交媒体网站。我尝试了以下两种方法 -
$cordovaSocialSharing
.share(message, subject, file, link)
和
$cordovaSocialSharing
.shareViaTwitter(message, image, link)
现在我的问题是 -
N.B。 :我已经非常困扰Google了。
提前致谢。
答案 0 :(得分:0)
我的问题是传递了一个错误的filePath,所以我找到了一个类似下面的解决方案:
import {CaptureError, MediaFile, MediaCapture, CaptureImageOptions, Transfer} from "ionic-native";`
declare let cordova: any;
private static options = {
message: '', // not supported on some apps (Facebook, Instagram)
subject: '', // for email
files: [''], // an array of filenames either locally or remotely
url: ''
};
videoOptions: CaptureImageOptions = {limit: 1};
videoData: any;
captureVideo() {
MediaCapture.captureVideo(this.videoOptions)
.then(
(data: MediaFile[]) => {
this.videoData = data[0];
const fileTransfer = new Transfer();
fileTransfer.download(this.videoData.fullPath, cordova.file.applicationStorageDirectory + 'fileDir/filename.mp4').then((entry) => {
this.options.message = " Your message";
this.options.subject = "Your Subject";
this.options.files = [entry.toURL()];
this.options.url = "https://www.google.com.tr/";
SocialSharing.shareWithOptions(this.options);
}, (error) => {
});
},
(err: CaptureError) => {
}
);
}
如上所示,我只是将视频文件复制到 applicationStorageDirectory