How to embed mp3 files in IOS/Android/WebAssembly with UnoPlatform - android

I am attempting to build a UnoPlatform app which has the capability to play some embedded mp3 sound effect files.
Using MediaPlayerElement, it is straight-forward to play media from HTTP sources, however it seems there must be some platform specific hoops to jump through to get embedded resource files to play.
The following event handler works for UWP, but not IOS, Android, or WebAssembly:
private void SpinButton_OnClick(object sender, RoutedEventArgs e)
{
player1.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/Sound.mp3"));
}
I have attempted to follow the info here https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/mediaelement for how to embed the media on IOS, but it does not seem to work for me.
Is there a trick to this? is there a sample out there with this working?

The current implementation of the MediaPlayerElement is still a bit limited, but playing back mp3 on Android and iOS should be supported.
The trick is to put the .mp3 files in the right location as they are not yet (as compared to image files) automatically copied over to the correct platform-specific location during build. In case of Android, you need to put the audio files in the Assets folder, for example:
And the Build Action needs to be set to AndroidAsset.
In case of iOS, the files go to the Resources folder and have the Build Action set to Bundle Resource.
You can now reference the files as if they were in fact in the "Assets" folder, using the ms-appx: URI scheme:
<Grid>
<MediaPlayerElement AutoPlay="True" Source="ms-appx:///Assets/test.mp3" />
</Grid>
This is just a quick example, but hopefully you can use it as a starting point. Whenever in doubt, it is quite useful to browse the source code of the respective features on GitHub, for example here is the media file loading implementation for Android.
For WebAssembly, MediaPlayerElement is not supported yet, but if you want to see it supported soon, please vote up on this issue.

Related

HTML5 audio blob would not play on Android

I'm serving an audio file (WAV file that contains a short uncompressed PCM) from my GAE app using BlobStore.
On a click event, I set audio.src and call audio.play().
Now here is the weird part:
When working locally - it plays well on both IOS and Android.
After deploying to GAE, it plays well on IOS - but not on Android!
No error is shown - it just plays nothing.
As far as I can tell from GAE logs, the audio file is served in all cases.
In case of Android I can see a requests from "Player/LG Player 1.0 for Android 4.4.2 (stagefright alternative)".
Any idea what's going on, or how to debug this?
Update
Tried playing files from Google Cloud Storage, according to Stuart Langley's suggestion.
In that case, Android plays well, and IOS doesn't (intermittently. Sometimes gives an error).
So a workaround that works for me is storing the file on Cloud Storage, and also calling createGsBlobKey in order to serve it as a blob.
On the client side I check whether it's Android (navigator.userAgent.match(/Android/i)). In case of Android I set audio.src to the Cloud Storage file, and in case of IOS I set it to my servlet which serves the file using BlobstoreService.serve with the blob key I got from createGsBlobKey.
This is a cumbersome workaround and I didn't check other mobile OSs to see what works for each, so if anyone has a better solution please let me know.
Most likely this is due to the chunked response when serving a blob.
Here is an issue tracker item about audio files not playing correctly in some browsers.
Here is a test web site I put together while back that illustrates the problem.
As for workarounds - You can put the file on cloud storage and then play it from there, as long as you're not concerned about people hotlinking the file.

phoneGap: select audio file from device and upload

I am new to phoneGap. I am creating a dummy app to upload an audio file from iOS/android device on local server. So I was wondering if there is a way to open the audio gallery and select the required audio file to upload. Similar to an image gallery.
Is it possible to open audio list and select necessary audio file? If not, what is the alternative?
As far as I remember, you cannot reach the pictures and audio files stored in the media gallery. Therefore, you may need to implement your own native plugin and call the appropriate methods from your JavaScript code.
You can capture audio/image by using Capture plugin of Phonegap. Check this out Capture Plugin
You can perform basic File operations as well. Check this out File Plugin
For your situation, you have to implement native interface which can be accessed by your JavaScript code. This would be an alternative way for it. If you desire to create your own plugin, please have a look at Plugin Development Guide. This might be helpful.
Well I have implemented code using file plugin which will iterate through all the folders recursively to find all the image (created this as I needed multi selection approach which is not directly provided by cordova) . You can modify the extension of image (search) i.e png,jpeg etc with audio extension.
With this code you will get the path of audio files and you can make use of filetransfer to upload it on server
Hope it helps you

Choose which audio file format to use between Android and IOS?

In my app,I want to make sure user can record his sound and sent to other user to listen to it.
In android platform I choose .amr ,it's not too big and easy to record.
Then I realized I should make sure my ios user can chat with my android user,but .amr seems not support in ios(after v4.3).
So is there a certain audio file format that can use between android and ios platform?
Or I have to let my Server to do the Transcoding job?
Both android and iOS should be able to handle mp3 files.
You can encode to mp3 on the device using various open source projects (could be a combination of steps).
I would personally go for a server-side encoding/conversion, because too many things can go wrong (especially on all the various Android versions and devices)
At last we use amr. Ios client do the decode job.

Playing local audio file in Android webview app

I have a simple Android webview app, built with Phonegap Build. When trying to play a local mp3 file that's included in the APK, nothing happens. However, if I pull an mp3 from the web it works.
e.g.
<audio src="www.example.com/01.mp3" > WORKS JUST FINE
<audio src="01.mp3" > DOES NOT WORK
I'm new to Android development, so I can only guess that the file is somehow inaccessible by Android's media player. Here's a link to the errors/warnings from my log file if that helps shed any light on the problem.
http://pastebin.com/isS542RE
I have it working using Phonegap's Media class. I must have been doing something wrong initially, but I'm not sure what. The proper way to access it through the media object is as Simon stated previously:
myMedia = new Media("/android_asset/www/test.mp3");
You have to put the full path as the media class defaults to the /SDCARD directory on relative paths.
Simon also has a great write up about using the media class:
http://simonmacdonald.blogspot.com/2011/05/using-media-class-in-phonegap.html?m=1
As for the HTML5 method and using the AUDIO tag, I'm still not certain why it fails on local files. Phonegap's media class works just fine though and is probably a more reliable solution anyhow. Phonegap FTW!
Have you tried pointing the file to the local file system path using "file:///android_assets/01.mp3" assuming your .mp3 is within the applications assets directory?
We had the same problem, the media files, in order to be played, needs to be in the external storage dir. Try to move your HTML and related files to /mnt/sdcard/.
I filed an official bug report on this:
http://code.google.com/p/android/issues/detail?id=41995&thanks=41995&ts=1356643666

Phonegap Android App - Display Store MP3 Media

I've been following this blog to help me make a simple music player function with an Android app (http://simonmacdonald.blogspot.com/2011/05/using-media-class-in-phonegap.html).
All works well - but I would like some way to extract a list of all music media stored on the phone so the user can click a file and play it. Does anyone know if this is possible via phone gap? I'd need to access track name/artist etc and a link to the track.
Cheers
Paul
Prognosis is not good.... PhoneGap does not have an API for accessing the media library. So, you would have to fall back to the File API to locate music files, and then... you would have to read the binary data in the actual files to extract out the track/artist metadata. Ouch. Seems pretty impractical.
[EDIT]
By the way, PhoneGap is not the only game in town. Appcelerator seems to solve the same problem, and apparently has a richer API, which includes
access to media metadata

Categories

Resources