Comments (10)
So I have worked around this by downloading the video locally using the Capacitor FileSystem API, then sending the localUri to the saveMedia function. Once downloading locally, this function works.
@stewwan - It would be helpful to others if the requirement of downloading locally was added to the ReadMe. Hopefully this will help someone else. Cheers!
from media.
This is my working code of saving recorded video to iphone gallery album. Video is stored in tmp folder of application.
this.state.videoUrl = "capacitor://myapp.com/capacitor_file/private/var/mobile/Containers/Data/Application/1F68250A-EB4B-475A-93E0-FE4F0C5C2C74/tmp/E97451DA-6D4E-46E1-8D4B-5ACDE0EC87F4.mp4"
write file plugin: github
import {Capacitor, Plugins, FilesystemDirectory } from "@capacitor/core";
import { Media } from "@capacitor-community/media";
import { writeFile } from "capacitor-blob-writer";
const media = new Media();
saveVideo = async () => {
if (Capacitor.isNative) {
var convertedUrl = Capacitor.convertFileSrc(this.state.videoUrl);
const platform = Capacitor.getPlatform();
const albumName = "Album Name";
let albumIdentifier = "";
const res = await fetch(convertedUrl);
const blob = await res.blob();
var uri = await writeFile({
path: "media/videos/video.mp4",
directory: FilesystemDirectory.Data,
data: blob,
recursive: true,
fallback: (err) => {
console.log(err);
return process.env.NODE_ENV === "production";
},
});
if (platform === "ios") {
// Handle albums
let albums = await media.getAlbums();
albumIdentifier =
albums.albums.find((a) => a.name === albumName)?.identifier || null;
console.log("album: " + albumIdentifier);
if (!albumIdentifier) {
console.log("Creating album");
// Doesn't exist, create new album
await media.createAlbum({ name: albumName });
albums = await media.getAlbums();
albumIdentifier = albums.albums.find((a) => a.name === albumName)
?.identifier;
}
} else if (platform === "android") {
await media.createAlbum({ name: albumName });
}
media
.saveVideo({
path: uri.uri,
album: platform === "ios" ? albumIdentifier : albumName,
})
.then((r) => console.log(r))
.catch((e) => console.error(e));
}
};
from media.
Confirmed same issue when deployed directly to my device. iPhone 7 iOS 13.6.
I should also mention the CreateAlbum and GetAlbum functions both successfully execute on both the Simulator and my device.
The SavePhoto function is also working, with a remote url as well.
Yet the SaveVideo function throws the error listed in the first post above.
from media.
Hi @stewwan --
Any suggestions related to this issue? I appreciate your assistance.
from media.
@oconcept Does your code work on android too? I can see in your code that you have console.log("album found!");
I'm still trying to find a work around on getAlbums returning Album already exists
mentioned here #6
from media.
Hi @amakh - I haven't tested on android yet. Reviewing the other thread, is this only an issue in the emulator for you? I saw a comment saying everything is working on a physical device, is that correct?
from media.
@oconcept Unfortunately it doesn't work on android either :/
Feel free to keep us updated on the other issue if you try on android 👍
from media.
This is my working code of saving recorded video to iphone gallery album. Video is stored in tmp folder of application.
this.state.videoUrl = "capacitor://myapp.com/capacitor_file/private/var/mobile/Containers/Data/Application/1F68250A-EB4B-475A-93E0-FE4F0C5C2C74/tmp/E97451DA-6D4E-46E1-8D4B-5ACDE0EC87F4.mp4"
write file plugin: githubimport {Capacitor, Plugins, FilesystemDirectory } from "@capacitor/core"; import { Media } from "@capacitor-community/media"; import { writeFile } from "capacitor-blob-writer"; const media = new Media(); saveVideo = async () => { if (Capacitor.isNative) { var convertedUrl = Capacitor.convertFileSrc(this.state.videoUrl); const platform = Capacitor.getPlatform(); const albumName = "Album Name"; let albumIdentifier = ""; const res = await fetch(convertedUrl); const blob = await res.blob(); var uri = await writeFile({ path: "media/videos/video.mp4", directory: FilesystemDirectory.Data, data: blob, recursive: true, fallback: (err) => { console.log(err); return process.env.NODE_ENV === "production"; }, }); if (platform === "ios") { // Handle albums let albums = await media.getAlbums(); albumIdentifier = albums.albums.find((a) => a.name === albumName)?.identifier || null; console.log("album: " + albumIdentifier); if (!albumIdentifier) { console.log("Creating album"); // Doesn't exist, create new album await media.createAlbum({ name: albumName }); albums = await media.getAlbums(); albumIdentifier = albums.albums.find((a) => a.name === albumName) ?.identifier; } } else if (platform === "android") { await media.createAlbum({ name: albumName }); } media .saveVideo({ path: uri.uri, album: platform === "ios" ? albumIdentifier : albumName, }) .then((r) => console.log(r)) .catch((e) => console.error(e)); } };
Hey @mcarnoky001, I am trying to save a video from a URL to an iphone's local photo roll. Would you mind please sharing the part of your code that accomplishes this?
Apologies if you've already referenced that code here, but I'm basically wondering how you generate this path:
this.state.videoUrl = "capacitor://myapp.com/capacitor_file/private/var/mobile/Containers/Data/Application/1F68250A-EB4B-475A-93E0-FE4F0C5C2C74/tmp/E97451DA-6D4E-46E1-8D4B-5ACDE0EC87F4.mp4"
Thanks!
Are you just using the capacitor-blob-writer
package to save the video to local photo roll?
from media.
@mepc36 Im using a plugin, which returns the given path. https://github.com/TeamHive/capacitor-video-recorder
from media.
can you try with latest plugin v3 ?
from media.
Related Issues (20)
- Error while copying media file HOT 10
- Media.savePhoto's Promise<PhotoResponse> returns 'undefined' on iOS HOT 2
- Read file path from platform-specific identifier on iOS HOT 1
- docs(android): make it clear that file return on savePhoto is only available on Android
- App crash after downloading an image HOT 8
- App is crashed on Android due to EACCES (Permission denied) HOT 11
- Is there any method to retrieve more photos like using offset in query? HOT 1
- feat(android): add getAlbumsPath() function to get where albums are stored on filesystem
- Error: RuntimeException occurred : In SaveVideo method HOT 1
- READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE are still required in Android 13 HOT 5
- RuntimeException occurred / EACCES (Permission denied) when trying to save a photo/gif/video on android < 13 HOT 12
- When wanting to save photo to Album with identifier, getting identifier doesnt exist even tho Album exist HOT 3
- feat(ios): support jpeg files instead of png HOT 3
- Camera plugin is not implement on Android (Capacitor Camera) when pairing with Capacitor-Community/Media HOT 2
- savePhoto is not working in android 8.1.0 Samsung SM-T580 tablet HOT 1
- MediaFetchOptions support individual photo for high resolution HOT 2
- feat(ios): get specific media by identifier HOT 9
- feat: has access right / error codes for all errors HOT 5
- feat: Capacitor 6 Support HOT 4
- Failed to parse source map HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from media.