how to save realtime recording file to google drive - android

I'm developing android app that recording voice and upload to google drive.
The simple solution is to save recording file to the local cache directory and then upload that file to google drive using google drive api.
But I want to upload recording file to google drive directly not saving into local cache directory.
Like this
recorder = MediaRecorder()
.apply {
setAudioSource(MediaRecorder.AudioSource.MIC)
setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
setOutputFile('googleDrivePath')
prepare()
}
recorder?.start()
But I don't know how to get google drive path

According to the docs:
Set the output file name using setOutputFile(). You must specify a file descriptor that represents an actual file.
As I also can’t find a way to retrieve the file as a byte array on a MediaRecorder in the javadoc, or redirect it to an OutputStream, I think I can assume it is impossible to not write it to a file.

Related

How And Where Do Meditation Apps Store Their Audio Files?

I'm building a Flutter app that plays audio files. I have hundreds of audio files that are too large to store in the app. So, I want to host the files, then stream them to the device.
I'm using the just_audio package (https://pub.dev/packages/just_audio). I've tested my code using the following hosted audio file and it works... (https://www.learningcontainer.com/wp-content/uploads/2020/02/Kalimba.mp3)
However, when I try to play my own audio files from Google Storage it doesn't work. Google gives me a storage location that looks like this (gs://myappname.appspot.com/audio_file.WAV)
So I guess I have two questions.
Is it possible to stream audio files from Google Storage to an iOS or Android app? If so, what am I not doing right? Or should I be using another Google service for this?
If this is not possible, how do apps like Headspace or Calm host and then stream their audio files?
Any advice would be greatly appreciated.
In an attempt to be thorough, here are the rules for my google storage account...
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
// allow access for all users
allow read, write;
}
}
}
I solved this. I was using the wrong address in Google Storage.
Google Storage gives a "storage location" which is the gs:// address I was using. It also gives a download link that I missed.
By using the download link, I solved my problem.

How to upload files using the Google Drive API?

I'm trying to upload a file using the Google Drive api on Android
https://github.com/googlesamples/google-services/tree/master/android/signin/app/src/main/java/com/google/samples/quickstart/signin
I signed up to SignInActivityWithDrive.java in the link above.
But there is no example of uploading a file, downloading a file
I want to know how to upload and download files
Thank you
You can find basic examples of uploading and downloading in the docs.
Uploading
You can send upload requests in any of the following ways:
Simple upload: uploadType=media. For quick transfer of a small file (5 MB or less). To perform a simple upload, refer to
Performing a Simple Upload.
Multipart upload: uploadType=multipart. For quick transfer of a small file (5 MB or less) and metadata describing the file, all in
a single request. To perform a multipart upload, refer to
Performing a Multipart Upload.
Resumable upload: uploadType=resumable. For more reliable transfer, especially important with large files. Resumable uploads
are a good choice for most applications, since they also work for
small files at the cost of one additional HTTP request per upload.
To perform a resumable upload, refer to Performing a Resumable
Upload.
The following example shows how to upload an image using the client libraries:
File fileMetadata = new File();
fileMetadata.setName("photo.jpg");
java.io.File filePath = new java.io.File("files/photo.jpg");
FileContent mediaContent = new FileContent("image/jpeg", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute();
System.out.println("File ID: " + file.getId());
Downloading
Depending on the type of download you'd like to perform — a file, a
Google Document, or a content link — you'll use one of the following
URLs:
Download a file — files.get with alt=media file resource
Download and export a Google Doc — files.export
Link a user to a file — webContentLink from the file resource
An example of a basic download is:
String fileId = "0BwwA4oUTeiV1UVNwOHItT0xfa2M";
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().get(fileId)
.executeMediaAndDownloadTo(outputStream);
It is 2022 now, and how the Google Drive API works might have changed significantly. I needed to upload a number of large files from a remote server where I have terminal access. This is how I got it working for me:
Use the steps detailed in this link to create a Google Services API (on your local computer) and get the API credentials. An extra step was required before step 3, go to the 'OAuth consent screen' tab on the panel to the left and complete necessary steps required. You have to do this only once. For free google accounts, you'll have to select External as the API type (but you can always keep the api in testing mode to not allow others to use it). Also add the gmail address you wish to use as a test user in this panel. Continue the rest of the steps from the aforementioned link.
From Step 1 you should get a client_secret_XXXXX.json file. Copy it to your remote computer working directory using SCP. Rename the file to client_secrets.json.
pip install pydrive
Import and run the following inside the remote working directory.
from pydrive.auth import GoogleAuth
gauth = GoogleAuth()
gauth.CommandLineAuth()
It will provide you a link that you can use to log into your google account from your local computer. You will get a login key that you will have paste into your remote terminal.
Upload a list of filenames
from pydrive.drive import GoogleDrive
drive = GoogleDrive(gauth)
for filename in filename_list:
## Enter folder ID here.
## You can get the folder Id from your drive link e.g.,
## https://drive.google.com/drive/u/2/folders/1pzschX3uMbxU0lB5WZ6IlEEeAUE8MZ-t
gfile = drive.CreateFile({'parents': [{'id': '1pzschX3uMbxU0lB5WZ6IlEEeAUE8MZ-t'}]})
gfile.SetContentFile(filename)
gfile.Upload() # Upload the file.

Get file from Google Drive via shared link

I'm making something like online journal app, that will download "journal file" from Google Drive (via shared link) once and will update that file if it changes. Please, can anyone point me to some guides how to do it. I already tried to pin file from drive, but I don't really understand what to do next..
Downloading Files from Google Drive:
To download a Google Drive file via link, try this (from this tutorial):
https://drive.google.com/uc?export=download&id=FILE_ID
Just replace the FILE_ID with the original fileID found in the Drive URL.
Additonal notes:
You can download files using the DRIVE REST API
To download files, you make an authorized HTTP GET request to the file's resource URL and include the query parameter alt=media. For example:
GET https://www.googleapis.com/drive/v3/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media
Authorization: Bearer ya29.AHESVbXTUv5mHMo3RYfmS1YJonjzzdTOFZwvyOAUVhrs
Downloading the file requires the user to have at least read access. Additionally, your app must be authorized with a scope that allows reading of file content. For example, an app using the drive.readonly.metadata scope would not be authorized to download the file contents. Users with edit permission may restrict downloading by read-only users by setting the viewersCanCopyContent field to true.
Updating files in Google Drive
Make an HTTP Request to Google Drive using PATCH. The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request- URI. Things to take note of are:
Parameters
Authorization
Request Body

Universal Music Player with own JSON and Youtube Audio Library

As mentioned in this line:
private static final String CATALOG_URL =
"http://storage.googleapis.com/automotive-media/music.json";
This file contains a list of tracks that are hosted by Google online.
So, I guess the complete URL of Jazz_In_Paris.mp3 would be
https://www.youtube.com/audiolibrary/music/Jazz_In_Paris.mp3
but getting 404 Not Found in a same way I have tried
https://www.youtube.com/audiolibrary/music/album_art.jpg
but again same result 404 Not Found
So here are my few small questions:
1. What is the complete URL of `Jazz_In_Paris.mp3` and `album_art.jpg`
2. Where they have used site object "site" : "https://www.youtube.com/audiolibrary/music" in application (in which class and where)
3. Where I have to make changes in my code, If I would like to get JSON from my own Server "http://www.domain.com/services/music.json"
4. How can I create my own Youtube Audio Library, Like in my Library I would like to add my favourite youtube songs
What is the complete URL of Jazz_In_Paris.mp3 and album_art.jpg
http://storage.googleapis.com/automotive-media/album_art.jpg
http://storage.googleapis.com/automotive-media/The_Messenger.mp3
Where they have used site object "site" : "https://www.youtube.com/audiolibrary/music" in application (in which class and where)
this url not used any where in app.
Where I have to make changes in my code, If I would like to get JSON from my own Server "http://www.domain.com/services/music.json"
yes, you can use same json for your app but just change path to your server(just create same json format)
How can I create my own Youtube Audio Library, Like in my Library I would like to add my favourite youtube songs
Universal Music Player: use Google storage client to store music files but you can also create own you tube channel and make private video. use it in your app
EDITED:
"site" json object is useless. this object is json because of previous version of app they have used that. currently not.
youtube channel and Google storage both are different thing. Google storage mainly used to store files which we are able to use in our app.
in you tube every one can upload video which is private/public(if you are going to use that in your app then use private). for more detail check you support articals
i suggest you to use Google Storage API or you can also upload files on your own server!

Phonegap Media API trying to access audio locally

I am currently working on an app that has to play audio from an external source. It is in the .amr file format, but giving it the URL and looking at log cat I can see its trying to access it locally logging:
FAILED renaming /storage/sdcard0/tmprecording.3gp to /storage/sdcard0/http://URL/audio.amr
Here is my player code
function play(source) {
var media = new Media(source, Played, Failed);
media.play();
document.getElementById('status').innerHTML = "playing";
}
with the function linked to a button and given a URL to the audio. I am testing this out on Android.
Thanks!
Never mind, it was just an issue with formats, .amr is an incompatible format so it didnt work

Categories

Resources