Audio on Mobile apps - android

I am new to apps development, so I apologize if I am asking something which may seem simple.
I am building a hybrid application using ionic. Everything was smooth until I tried to play audio. I am trying to play an HLS audio stream and some mp3 files located on a web server.
After a research on the internet and various tests using players, I used the video.js. After some tests I figured out, that the player was not responding to android versions prior to 4.4.2. ...and I haven't yet made any test on IOS.
I am realy confused on how I can play audio on a hybrid mobile application.
Any help is much appreciated!

The audio feature in Ionic Framework can be implemented by using the Apache Cordova Media plugin, and ngCordova.
Install the plugin by running the following ,
cordova plugin add org.apache.cordova.media
1.Play audio file from internet
html
<button class="button" ng-click="play('http://www.stephaniequinn.com/Music/Commercial%20DEMO%20-%2013.mp3')">Play from internet</button>
1.play a song from the file system
html
<button class="button" ng-click="play('www/mp3/song.mp3')">Play from file system</button>
controller
$scope.play = function(src) {
var media = new Media(src, null, null, mediaStatusCallback);
$cordovaMedia.play(media);
}
it will try to play song from /storage/emulated/0/www/mp3/song.mp3
Please refer this blog.You will get more idea.If you have any doubt,please let me know,thanks

If you're playing audio and it is essential to your app, you should think about programming an audio service (in Java). When the user navigates to another app and the system is under heavy load, the use of an audio service prevents the OS from killing your audio along with your activities.
Also, when audio playback gets into the app, you must make sure that the playback stops when a phone call arrives or the app loses the audio focus. I don't know, whether or not you can handle all of this with ionic and I also don't know your coding skills. But handling audio on Android can quickly become a very complex task. Hence I recommend a separate service, that works as an encapsulated component.

Related

Cordova Plugin to display audio information and controls on iOS and Android Lockscreen

I am looking for a plugin or plugins that would allow me to show audio metadata (Title, Artwork etc.) on the Lockscreen of both iOS and Android.
Along with that I would like to control the audio from the lockscreen (Play pause etc, it already happens in iOS I need it happen on Android).
Lastly the plugin should provide audio information within the control center in iOS and the notification area in Android of cause with the ability to Play Pause etc.
If it is easier to do with some native code tweaks then can someone please point that out also to a tutorial as to how it can be done.
Below are some examples of what I am speaking about
This plugin does what you're looking for: https://github.com/homerours/cordova-music-controls-plugin
As of writing it has a few issues with iOS html5 audio (see https://github.com/homerours/cordova-music-controls-plugin/issues/97 and https://github.com/homerours/cordova-music-controls-plugin/issues/66) but works across iOS, android and windows phone.
You could also try this, however I have never tried it. It uses the native players for iOS and Android, and will not work on chrome or your dev machine.
https://github.com/wnyc/cordova-plugin-playerhater
On my current project I have much the same need as you, (I am using HTML5 audio) and have had to put together a number of different plugins.
iOS Background Audio
https://github.com/AubreyHewes/cordova-background-audio
iOS Meta data:
https://github.com/ChoiZ/NowPlaying
https://github.com/shi11/RemoteControls
I am working on a solution for a modular android audio notification controls using the webintent plugin, but I am far from finishing it. I'll post back here when it's done.

Audio is not being played when I convert the html5 game to Android using PhoneGap Cloud Build service

I had purchased an HTML5 game named BattleBattle from envato market. It is working fine in my pc when I publish it using IIS. I tried to convert this game to android apk file using PhoneGap Cloud Build service. The apk file is being generated and I am able to install and play the game in my mobile but the only problem is that there is no sound playing whereas sound plays in the browser. What could be the reason? The game is developed using Construct. I searched for solutions online but nothing helped. I even tried including audio plugins for phonegap but that too didn't help. Could anyone help me to solve this problem?
You need to use the core media plugin. https://build.phonegap.com/plugins/1168 and play the audio using it.
You will have to dig into the code and change the way the audio is initiated. Also remember that you will be only allowed to play one file at a time.

Detecting Spotify Song Plays

I'm working on a mobile application that detects song plays from various media players, both on iPhone and Android. We currently support a number of applications in both platforms. Our application works in a similar way to how Last.FM detects and automatically scrobbles plays.
However, we have not been able to get a working solution for detecting Spotify song plays that does not need to use either Last.FM scrobbling (available in Spotify for Android only) or Facebook as a proxy.
I've tried a few things for android but as I understand it (I see lots of posts e.g. Find what song is playing in spotify on android), the Android Application does not broadcasts media related intents for song plays, so we need something more creative. In any case this does not solve our problem for the iPhone use case.
Lib-spotify held some promise for us, and I've manged to build an application that can create a session and navigate some playlists, but I have not figured out if I can load what would appear as "play history" in the Desktop Application via lib-spotify (e.g. is this a special form of playlist?). I have also tried a Spotify App to accomplish the same but the API appears to not to expose required functionality.
It seems like I've exhausted all avenues on this one, but does anybody have any suggestions for something I haven't tried?
Assume that I have spotify credentials for each user whose history I would like to gather.
Thanks
Spotify has a metadatachanged intent-action that contains artist, album, track, length, and id values.
See: https://stackoverflow.com/a/22195867/1345586
Unfortunately, the desktop play history is local to each machine, meaning it can't be accessed through libspotify or any other API.
At the moment, there isn't a way to reliably achieve what you're wanting to do on mobile platforms.

wayout to play audio in android app without Java code

I am planning to create a music app which allows user to choose from a number of inbuilt audio. The closest thing I found on the web was jPlayer plugin for jQuery which I couldn't make it work on Android. My app is based on jQuery mobile.
Is there any really simple way to add audio to my web app which I am planning to convert to .apk using phonegap. I intend to provide a list of links/file names to user in my app and on clicking the file name/link, the audio player controls shall be displayed and the selected audio shall start playing.
I have also tried the HTML embed tag and it also didn't work in the apk.
PhoneGap doesn't support the tag yet as far as I know.
I have heard of people successfully using the PhoneGap API +jQuery Mobile to get it working via this tutorial: http://www.mobiledevelopersolutions.com/home/start/twominutetutorials/tmt1part1
Looks like you can use a PhoneGap plugin to do this:
window.plugins.webintent.startActivity({
action: WebIntent.ACTION_VIEW,
url: 'http"//whatever.mp4'},
function() {console.log('Wow this actually worked!');},
function() {console.log('Failed to open URL via Android Intent');}
);
https://groups.google.com/forum/?fromgroups=#!topic/phonegap/nEm47r1Bhak

video via phonegap on android

I have been trying to play video in my android application that I made using phonegap. I had several problems and so I have several questions.
Firstly, does html5 video tag work with phonegap? I couldn't succeed to write the html5 codes.
Secondly, what types of videos are supported by android and phonegap?
Thirdly, I try to play a file whose extension is mp4. There is no scene on the screen but I can hear the voice of the video. What can be the reason?
Thanks in advance.
Nope, the video tag is broken in most if not all versions of Android. Go star these issues:
http://code.google.com/p/android/issues/detail?id=22254 and
http://code.google.com/p/android/issues/detail?id=8272
In order to work around this pain in the #$$ I've written a plugin you can use on Android to play videos.
http://simonmacdonald.blogspot.com/2011/11/video-player-plugin-for-phonegap.html

Categories

Resources