Android: is therey anyway to volume control by javascript - android

Android : Phonegap has javasript functions to to play,pause,resume & stop the media player. Is there any way to control the volume(increase/decrease) by javascripst function.
1.phonegap.js file included
in html page :
<html>
<head> <script>
var my_media = null;
var mediaTimer = null;
function playAudio(src) {
my_media = new Media(src, onSuccess, onError);
my_media.play();
....
}
</script> </head> <body>
Play Audio
</body> </html>
in java class :
...
super.loadUrl("file:///android_asset/www/testmus.html");

I know this question is fairly old, but I came across it looking for something else.
There is a newish and not well-documented function on the PhoneGap Media class for Android:
setVolume()
So using the example above:
// level is a value from 0-100
var level = 50;
my_media.setVolume(level);
It's not heavily documented because I believe it's only on Android.

This is old, but as we were just solving this issue, I thought I'd put it up here.
The cordova my_media.setVolume(level); doesn't actually set the master volume of your audio stream, it just sets the volume of your audio asset relative to the overall audio stream's volume. For instance, if I have my device's music player stream set to half of the maximum, and I am playing my audio into the music player stream, then the loudest I can ever make it is half of maximum volume. For our uses, this was not enough.
To get around this, you can create an audio slider for your specific audio stream, hide it, and then programmatically set the slider's volume. This was figured out for ios and explained here -iOS 7: MPMusicPlayerController volume deprecated. How to change device volume now?
The code to create controllable audio sliders using cordova was originally done for ios, and then it was forked to Android. I would post the links, but I'm link-limited due to my non-existent reputation.
We combined these two, added in the ios volume control code, and then ported that over to Android as well so that there is now a cordova library to allow for Andoid and iOS music stream volume control here - https://github.com/shibbs/VolumeSlider
We have created a pull request to merge our version of the audio controller in with the devgeeks cordova volume controller code, but for the time being, the place to get it will be from the shibbs/ linked above.
A code snippet showing how you would go about it is :
my_media = new Media(soundFile, onSuccess, onError); //create the media object
my_media.setVolume(1.0); //set your volume to w/e you want, we maxed it
volumeSlider = plugins.volumeSlider; //create the volume slider object
volumeSlider.createVolumeSlider(10,350,300,30); // origin x, origin y, width, height
volumeSlider.setVolumeSlider(1.0); //set your volume slider value to between 0 and 1
volumeSlider.resetVolumeSlider(); //this will reset the device volume to whatever it was set to when you created the volumeSlider.

You would have to do what (I assume) phonegap does and use a Javascript bridge to the existing Java functions that control the volume. Volume control is in adjustVolume and adjustStreamVolume(): you can add custom javascript handlers as shown here.

Related

Seek field of video node is not working properly

I am working on video player using video node of Scene Graph Component. My issue is when i set seek field like
m.video.seek = 20 it's start playing from 15 seconds or 18 seconds but not from exact position 20 seconds. My code is...
inner = createObject("RoSGNode", "ContentNode")
inner.url = "http://-------------.m3u8"
inner.streamformat = "hls"
inner.SwitchingStrategy = "full-adaptation"
Video file format is m3u8 and using ui_resolutions=fhd in manifest file of roku app.
Is this issue related to stream format or others? Please help me.
This is correct behavior you have "hls" streamformat, this is format specific, hls video stream is divided into chunks, so when you set seek, video will start from chunk start not from the middle of this chunk.
I solved this issue by setting video component attribute seekMode to "accurate"
<Video id="videoPlayer" visible="true" translation="[0, 0]" width="1920" height="1080" seekMode = "accurate" enableTrickPlay="true" enableUI="false"/>

Adjust Dash stream volume with Android Exoplayer

I'm trying to set up a seekbar to control the level of an instance of exoplayer streaming dash.
The setup I am using is a modified version of the demo project and am having trouble figuring out which element I should be trying to affect with the seekbars output ie how to use MSG_SET_VOLUME properly etc etc
Any input would be massively appreciated.
The end result I am looking for is an application with two instances of exoplayer both streaming dash content with a fader(seekbar) controlling the mix of the two players (which once this is figured out i presume should be easy enough if the maths is correct)
Again any help would be massively appreciated I have had a bit of a time with Exoplayer so far being such a novice! thanks guys!
If I read the ExoPlayer source code correctly you have to keep references to the audioRenderers you use when preparing the ExoPlayer instance.
exoPlayer.prepare(audioRenderer);
To change volume you have to send the following message:
exoPlayer.sendMessage(audioRenderer, MediaCodecAudioTrackRenderer.MSG_SET_VOLUME, 0.1f);
First you pass the audioRenderer for which you want to change the volume. Secondly you define the message which you want to send to the renderer which is MSG_SET_VOLUME, since you want to affect audio.
Finally you pass the value you want to set the volume to. In this example I chose 0.1f but of course you can use any value which fits your needs.
You can effect two different playback volumes if you send messages to both MediaCodecAudioTrackRenderers which you used to prepare playback. So you could send two messages with for example value 0.4f for audioRenderer1 and 0.6f for audioRenderer2 to blend the playbacks into one another.
I did not try this myself, but I think it should work.
This is the snippet of the original ExoPlayer code which is responsible for handling the MSG_SET_VOLUME message:
public void handleMessage(int messageType, Object message) throws ExoPlaybackException {
if (messageType == MSG_SET_VOLUME) {
audioTrack.setVolume((Float) message);
} else {
super.handleMessage(messageType, message);
}
}

HTML5 Audio doesn't show Timer when run on Android Device

I am developing a PhoneGap application that uses HTML5 Audio tag to run MP3 Audios. Although controls are on, but when the application is run on an Android phone the controls do not show up. All I can see is just the slider. In Ripple Emulator all works fine.
I am not interested in other controls but at least I should be able to display the timer.
Anyone can please suggest how can I do that.
Thanks!
Not sure whether i am right or wrong. few days back, i was struggled with integrating the audio and video tag for html5. Android browser doe'nt support the Audio/Video tag, for even i have given the controls for it, but then too it was not worked. What i done was, i used to define the script in-order to perform the mediafiles using Html5 tag.
String script = "<SCRIPT LANGUAGE=" + "JavaScript"
+ ">function playvideo(url){window.location=url;}</SCRIPT>";
include the above script in you html5, and let me know whether it works or not.
Note:
I used native activity for this.
I have explored and successfully replaced html5 audio with MediaElement.js
Here is my Audio tag:
<audio autoplay="autoplay" id="audioplayer" controls="true">
<source src="none" type="audio/mp3">
****
</audio>
And the following script simply converts the HTML5 audio player to MediaElement player with all the controls that I wanted to see:
$('audio').mediaelementplayer({
//audio { width: 250px; margin:10px;}
defaultAudioWidth: 300,
// default if the user doesn't specify
defaultAudioHeight: 30,
// width of audio player
audioWidth: 300,
// height of audio player
audioHeight: 30,
// initial volume when the player starts
startVolume: 1.0,
// useful for <audio> player loops
loop: false,
// enables Flash and Silverlight to resize to content size
enableAutosize: true,
// the order of controls you want on the control bar (and other plugins below)
features: ['playpause','progress','current','duration'],
// Hide controls when playing and mouse is not over the video
alwaysShowControls: false,
// force iPad's native controls
iPadUseNativeControls: false,
// force iPhone's native controls
iPhoneUseNativeControls: false,
// force Android's native controls
AndroidUseNativeControls: false,
// forces the hour marker (##:00:00)
alwaysShowHours: false,
// show framecount in timecode (##:00:00:00)
showTimecodeFrameCount: false,
// used when showTimecodeFrameCount is set to true
framesPerSecond: 25,
// turns keyboard support on and off for this instance
enableKeyboard: true,
// when this player starts, it will pause other players
pauseOtherPlayers: true,
// array of keyboard commands
keyActions: []
});
So this is a fantastic solution if anyone is looking for a nice replacement of HTML5 Audio.

Soundpool to file

I've got a SoundPool[] that I use to play mixed audio files.
Soundpools play together without any problem, and it's very efficient!
Very briefly:
private SoundPool[] sound = new SoundPool[C.ROWS];
// every sound is initizialized with a load()
// and when asked...
public void play(int row, int variation) {
if (mute[row]) return;
if (variation != 0)
sound[row].play(variation_scheme[row][variation-1], volume[row], volume[row], PRI, 0, 1f);
}
This is just to show! :)
I don't put other pieces of code because everything works very fine and it is not really a problem.
My question, instead, is:
how can I redirect the whole output of the application to a file, instead of (or in addition to) the audio speaker?
In other words, there are two main solutions:
1. how can I instruct AudioPool to play() the sounds to a file instead of to an audio device?
2. or how can I redirect all the audio output of my app (or even of all the phone) to a file?
Thank you.
The only way I found how to record audio is by recording each information of the sound being press such as, duration (using mediaplayer), soundID, millisecond time stamp to do play back to the millisecond, volume, rate (if needed). Then write these to a text file (internally or externally) for later use. Create a play back system that decodes that saved information from text file and organize it in some arrays or hashmaps and play back throught some sort of play back method with maybe using a handler and postDelay to play sound and desired time and then plug in necessary data to play sound from array or hashmap.
In this way you can have your own data files for playing sound sequences.

Getting audio volume during playback

I have some audio data (raw AAC) inside a byte array for playback. During playback, I need to get its volume/amplitude to draw (something like an audio wave when playing).
What I'm thinking now is to get the volume/amplitude of the current audio every 200 milliseconds and use that for drawing (using a canvas), but I'm not sure how to do that.
.
.
.
.
** 2011/07/13 add following **
Sorry just been delayed on other project until now.
What I tried is run the following codes in a thread, and playing my AAC audio.
a loop
{
// int v=audio.getStreamVolume(AudioManager.MODE_NORMAL);
// int v=audio.getStreamVolume(AudioManager.STREAM_MUSIC);
int v=audio.getStreamVolume(AudioManager.STREAM_DTMF);
// Tried 3 settings above
Log.i(HiCardConstants.TAG, "Volume - "+v);
try{Thread.sleep(200);}
catch(InterruptedException ie){}
}
But only get a fixed value, not dynamic volume...
And I also found a class named Visualizer, but unfortunately, my target platform is Android 2.2 ... :-(
Any suggestions are welcome :-)
After days and nights, I found that an Android app project called ringdroid
can solve my problem.
It helps me to get an audio gain value array, so that I can use to to draw my sound wave.
BTW, as my experience, some .AMR or .MP3 can't be parsed correctly, due to too low bitrate...

Categories

Resources