Ionic 3 get base64 audio string from recorded file - ionic-framework

I am using cordova-plugin-media to record voice(with pause and resume features) in my ionic app for android. After I record it I need to get base64 string in order to play it using html audio tag. And the problem is: if I am trying to save recording which was paused and resumed as 3gp file('voice.3gp'), then when I use readAsDataURL method of cordova-plugin-file, I don't receive anything(the callback simply not called). If I am trying to save it as mp3 or wav file, then I receive only 1st part of the recording(before pause). I suppose that the proper audio file extension should be 3gp as this extension is used in the implementation of 'cordova-plugin-media' but then I have problems with playing this file using html audio tag. Any help is appriciated

okay, I just found out that you can use method "resolveLocalFilesystemUrl" of the cordova-plugin-file which will return you the object and inside this object there is a property "nativeURL" which can be used as a source(src) for the video tag(had to video tag instead of audio because 3gp format is actually for video)

this.file.readAsDataURL(filePathtoUpload, this.fileName)
.then((base64Audio) => {
console.log(base64Audio);
})
.catch(function (err: TypeError) {
console.log("readAsDataURL: " + err);
});
this works for me

Read this:https://ionicframework.com/docs/v3/native/base64/
It is the oficial website API of ionic. Just install that plugin and use this:
this.base64.encodeFile(this.filePath + this.fileName).then(
(base64:any) =>{
console.log('file base64 encoding: ' + base64);
});
In this post, i explain it better. I let the link here:
convert audio file to base64 in ionic 3

Related

Recommended way to save audio stream to disk

The audio_service package manages streaming audio from a URL. Is there a way to simultaneously write the audio to disk as well?
Note: In python, one can do this by setting stream=True when calling requests methods. I'm looking for a way to do this via a flutter package.
The audio_service package manages streaming audio from a URL.
audio_service doesn't manage streaming audio, it manages your media notification. The way it works is: let's say you have already written an app that plays audio using some plugin XYZ, but you want to now just add a media notification so that your app can be controlled from the background. Then you use audio_service to wrap around your "existing" audio code.
So your question is really about what to do for your existing audio code which audio_service wraps around.
If you are following the audio_service official example, it demonstrates using the just_audio plugin to stream audio from a URL, so let's answer in terms of that. You can easily modify the official example by using just_audio's LockCachingAudioSource.
So for example, whenever in that example you see AudioSource.uri, just replace that code with LockCachingAudioSource and it will do what you want. That's it.
But to demonstrate some of the capabilities of LockCachingAudioSource in a bit more detail, here is a short demo of the way it works:
final source = LockCachingAudioSource(Uri.parse(url));
await player.setAudioSource(source);
await player.play();
The location of the cache file is by default chosen by the plugin, but you can obtain it here:
final cacheFile = await source.cacheFile;
You can clear the cache with:
await source.clearCache();
If you want to choose the location of the cache file, you can do so when constructing the source:
final source = LockCachingAudioSource(
Uri.parse(url),
cacheFile: File('/your/preferred/path.mp3'),
);

Download Result of Source Destination (Web Audio API)

I'm building a tool to edit audio with the Web Audio API.
Here is where I'm stuck:
...
source
.connect(gainNode)
.connect(analyser)
.connect(analyser2)
.connect(audioCtx.destination);
};
What I've written (which ends with the code above) successfully allows the user to upload a file, apply effects, and listen to it on play(). How would I then allow the user to click a button to export the results to a WAV file?
I've tried several methods online that have not worked for my use case.
Please let me know if more code is needed. Thank you for taking a look!
If you want a WAV file, I think you have to do that yourself. WAV files are quite simple. In this case, you'll need to add either a ScriptProcessorNode or AudioWorkletNode just before the destination to capture all the audio and convert it to a WAV file that can be downloaded.
If a compressed file is ok, you can look into MediaRecorder to save the data for you.
I ended up solving this by writing an entirely different script to download the file using OfflineAudioContext.
My original script plays the audio with effects, and the second script downloads it with the same effects. Now to figure out why there is latency on the effects while using OfflineAudioContext.

Playing audio on Smartface IO

I have been trying to play a sound on a click of a button and ive read everywhere and none of the solutions posted solved the problem.
I use the method stated on the docs website my file is an mp3 and its located in my resources/Sounds folder.
I have also read that there is a known issue in SMF. The only part that gets called in my playSound method below is the finished part
SMF.Multimedia.playSound("woop.wav",
true, true,
function() {
alert("started to play...");
},
function() {alert("finished")});
I have the audio file located in resources/sounds folder I have also tried moving it around and I have tried different file formats but without any luck.
Does anyone know a working method to play audio or any concrete info regarding this bug in SMF
Upload "woop.wav" into assets folder.Then use this code to play it.
SMF.Multimedia.playSound("woop.wav",true, false);
I tried both .mp3 and .wav files on Android,it works.Here is the official gudie for Multimedia.

Playlist file(m3u8) give another playlist file infinitely not giving any media file

I have a playlist file which give me another playlist file which also give me another playlist file, continously.
How can I play this playlist file? and Where can I found the source of video?
For example, I have a playlist file. That is
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=355670
http://slive.ytn.co.kr:1935/live/ylive_0624_1.sdp/playlist.m3u8?wowzasessionid=195968950
If I access to http://slive.ytn.co.kr:1935/live/ylive_0624_1.sdp/playlist.m3u8?wowzasessionid=195968950, it give me other playlist files.
#EXTM3U
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:894
#EXTINF:11,
media_894.ts?wowzasessionid=195968950
#EXTINF:10,
media_895.ts?wowzasessionid=195968950
#EXTINF:11,
media_896.ts?wowzasessionid=195968950
If I access to the results, it also give me playlist files.
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=373764
http://slive.ytn.co.kr:1935/live/ylive_0624_1.sdp/playlist.m3u8?wowzasessionid=1093961187
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=382539
http://slive.ytn.co.kr:1935/live/ylive_0624_1.sdp/playlist.m3u8?wowzasessionid=1566364859
etc...
Although I can play the url http://slive.ytn.co.kr:1935/live/ylive_0624_1.sdp/playlist.m3u8?wowzasessionid=195968950 in safari in my iphone, I want to play this url in my own iphone app.
How can I play m3u8 file extension by myself?
EDIT - May be a duplicate of this SO question but if you want to persist the file, you'll need to go the hard way listed below.
Easy way = Embed UIWebView in your app and initialize it with the url of the .m3u8 file. This will open up quicktime which understands m3u8 and it will play it as it downloads.
Hard way = manually create the request/responses for each part of the m3u8 session and then download each .ts file in turn from the playlist file. As you get each "chunk" of the video, write it to a file or memory, then append the next "chunk" after it. I've done this for a h.264 encoded .m4v file served as a m3u8 and it worked (my code is too ugly to paste) but the pseudocode is:
Fetch the m3u8, saving any cookies sent and any headers that may be important*
Parse the .m3u8 (the first file, with the #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=373764) and pull our the urls.
Fetch the playlist from one of the URLs in the .m3u8 file (being sure to keep any headers/cookies in the request that may be necessary)
Parse the playlist file, saving as much metadata as you need from the top part of the file, construct an absolute URL for each .ts path, then stuff it into an array.
Iterate over the array (again, being mindful of cookies/headers) and fetch the content of each .ts URL into a file.
Play the downloaded file with whichever Media Framework you choose (search SO for how to do this)
If you just need to play the files, go the easy route. If you need to persist them, you need to do the m3u8 dance.
*HTTP Scoop is invaluable for seeing how the m3u8 "protocol" works and for making sure you're request/response headers are accurate - http://tuffcode.com/
*I used vanilla NSURLConnection synchronous calls as my code was just a proof of concept, other network frameworks like AFNetworking will make this a lot easier.

youtube xml parser for iphone

I am working on iphone application which will read the following youtube page source:
view-source:http://www.youtube.com/user/danielmorcombefd
and then save the links of all the videos available on any particular youtube channel like the href node of the line below:
<h4><a class="title" href="/watch?v=ouMPBbZ2vKw&context=C2ab41ADOEgsToPDskJnhTjKl70yDQdEkLJb0So8" dir="ltr">
Can anybody suggest a source code link for youtube xml reader. Solutions are appreciate in advance
Alternate
You can also use the JSON format. You can add ?alt=json to the URL to get the JSON version of it. Then you can use JSON library. JSON library