how to programmatically increase/decrease volume using speech in Android - android-audiomanager

The goal here is to say "volume up" and for the volume to increase by 20% at a time by speaking that command for media playback. Not just to set it to max volume when the app starts. and conversely volume down. This is what I tried and it does not work.
AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
// Without volume control UI
To increase media player volume
audioManager.adjustVolume(AudioManager.ADJUST_RAISE,AudioManager.FLAG_PLAY_SOUND)
//To decrease media player volume
audioManager.adjustVolume(AudioManager.ADJUST_LOWER,AudioManager.FLAG_PLAY_SOUND)
My app uses Speech commands too launch apps I want to add the functionality of volume control and I'm a lil stuck, most of the code uses intents like similar to this format for basic commands like time, for instance, works as follows
if (command.indexOf("time") != -1) {
Date now = new Date();
String time = formatDateTime(this, now.getTime(),
FORMAT_SHOW_TIME);
speak("the time is " + time);
I would like it to raise or lower by 20% so I used the format of the following and can't get it to work Any help is appreciated..
else if (command.indexOf("Volume Up") !=-1) {
intent = new Intent(Intent.ACTION_VIEW,
intent.audioManager.adjustVolume(AudioManager.ADJUST_RAISE,AudioManager.FLAG_PLAY_SOUND));
}

Related

Is it possible to set dynamic marq text and logo into a video stream recording using libvlcsharp?

Good day to you all,
I have a problem, maybe someone can provide some helpful ideas on how to implement or if it's even possible:
I want to record RTSP stream from an IP-cam and I would like to add some text information and logo into the recording so it might be viewed when played back.
To do so I have first created one MediaPlayer element to connect to the IP-cam, duplicate onto the display, and recast via UDP.
using (var stream01_view = new Media(libVLC, "rtsp://192.168.10.214:5554",FromType.FromLocation))
{
stream01_view.AddOption(
":sout=#duplicate{" +
"dst=display{noaudio}," +
"dst=std{access=udp,mux=ts,dst=:1234}");
stream01_view.AddOption(":sout-keep");
player.Play(stream01_view);
}
The second stream connects to the local UDP cast and outputs to file
using (var stream01_record = new Media(libVLC, "udp://#:1234", FromType.FromLocation))
{
stream01_record.AddOption(":sout=#transcode{sfilter=marq}:file{mux=ts,dst=VideoMarqLogo.mp4}");
stream01_record.AddOption(":sout-keep");
recorder.Play(stream01_record);
}
Calling class MediaPlayer methods SetMarqueeInt and SetMarqueeString don't give the expected result.
Thanks mfkl for pointing to the right direction.
So the thing that does the trick is:
stream01_record.AddOption(":sout=#transcode{ vcodec=h264, scale=0.75, " +
"sfilter=marq{file='marq.txt',position=9}," +
"vfilter=logo{file='logo.png',position=6}}" +
":file{mux=ts,dst=VideoMarqLogo.mp4}");
A bit of a warning though, this piece of code is CPU intensive.
I'm left wondering if there could be a way to do this using GPU encoding.

Set Spotify playing position

I'm using the SpotifyAPI-NET on GitHub from JohnnyCrazy to play and pause songs on my Spotify desktop client. This works fine.
Now I want to change the playing position of the currently playing song. So I only want to say something like "SetPlayingPosition(64)" to play the current song from position "01:04". It seems that the SpotifyLocalAPI didn't support this feature.
To play and pause a song the API uses a message with the following format:
http://127.0.0.1:4381/remote/pause.json?pause=true&ref=&cors=&_=1520448230&oauth=oauth&csrf=csrf
I tried to find a summary of possible commands in this format, but I didn't find anything.
Is there something like http://127.0.0.1:4381/remote/seek.json... that I can use to seek to a specific position?
EDIT:
I tried to write my own method in the RemoteHandler class in the local portion of the SpotifyAPI. With this method I can set the position in the current playback.
Here's my code:
internal async Task SendPositionRequest(double playingPositionSec) //The desired playback position in seconds
{
StatusResponse status = GetNewStatus(); //Get the current status of the local desktop API
string trackUri = "spotify:track:" + status.Track.TrackResource.ParseUri().Id; //The URI of the current track
TimeSpan playingPositionTimeSpan = TimeSpan.FromSeconds(playingPositionSec);
string playingPosStr = playingPositionTimeSpan.ToString(#"mm\:ss"); //Convert the playingPosition to a string (Format mm:ss)
string playingContext = "spotify:artist:1EfwyuCzDQpCslZc8C9gkG";
await SendPlayRequest(trackUri + "#" + playingPosStr, playingContext);
if (!status.Playing) { await SendPauseRequest(); }
}
I need to call the SendPlayRequest() method with the correct playingContext because when the current song is part of a playlist and you call SendPlayRequest() without the context, the next song isn't from the playlist anymore.
But you can see that I use a fixed context at the moment.
So my question is now: How can I get the context (playlist, artist, ...) of the currently played song with the SpotifyLocalAPI?
The SeekPlayback method of the library you mentioned lets you seek through playback on whatever device your user is listening on. You can find the docs here.
Seeking playback is not currently possible using the Spotify Local API portion of that library.

android studio emulator volume stuck on low

I was trying to use MediaPlayer and AudioManager to change the volume of an audio file using app buttons. I seem to have messed up my emulator. The volume setting of the emulator and of my speakers is maxed but I can barely hear the sound file. Audio from other applications are working normally. I tried clearing the data from the emulator but that had no effect. Is there some way to reset the volume settings? I was using the following suggestions from other posts.
AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
int currVolume= am.getStreamVolume(AudioManager.STREAM_MUSIC);
currVolume++; // to change the volume
int maxVolume = 50;
float log1=(float)(Math.log(maxVolume-currVolume)/Math.log(maxVolume));
yourMediaPlayer.setVolume(1f-log1, 1f-log1);
Every time I executed this code on the emulator, the volume got lower and I can't bring it back up, no matter what I put in .setVolume()
The following has brought the volume back up. The currentVolume was 3 whereas the maxVolume is 15. I'm still not sure how mediaPlayer.setVolume() works.
AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
int maxVolume = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
audio.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, 0);

Windows Phone Background Audio current track is resetting

I am developing an WP8 app witch uses background audio agent. i have taken the background audio players sample. i have added the following method to audioplayer.cs
public static void playTrackAtIndex(int index)
{
currentTrackNumber = index;
BackgroundAudioPlayer.Instance.Track = _playList[currentTrackNumber];
}
after it is called the song at the specified index (let's say 5) will play, but when i pres skipnext in my ap or in the UVC currentTrackNumber is 0!. Please, any help is apreciated
it turns out you don't have any control over the lifecycle of the background audio agent, so at any time it may be killed and then instanced by the foreground app or the Background audio player. So the only whey to make the agent work is to design it as it will always be killed and instanced (use sql lite or files with a lock, or always check what backgoundaudioplayer is playing when your agent is called, so your agent will "remember" where it was before getting killed

LWUIT S40 Nokia Calendar Events with sound

I'm building an app to create events in the device Calendar, but when I have created them, all are set default without sound. I need to set the sound ON, when the user wants it.
How can I set the sound on the alarm in my created events?
Some guy from the nokia developer forum, solve my question.
He tells me that
You cannot access the Alarm from your Java app, but you can use the PIM API to create a Calendar event and add it (or better say import it) to the native Calendar app. The native Calendar application on Series 40 and Asha software platform devices, comes with a Reminder option that specifies how long before the event the user should get a notification sound about the event. This field can get several values (e.g. none, at start time, 5 minutes before, 10 minutes before etc). You can therefore specify a calendar event for a certain date and time and define its reminder attribute to "at start time". The calendar app doesn't allow you to specify the sound used for the reminder but rather uses the reminder tone defined in the device's sound settings under Settings > Sounds and vibra > Reminder tone (on asha software platform devices). The reminder uses the device's volume level. You cannot override neither the selected tone nor the volume level. So if the device is muted, when the reminder is activated there will be no generated sound, but otherwise the reminder should be heard in the tone and volume level set in the device's settings.
This is how you add an event with a reminder value set to "at start time" (tested on Nokia asha software platform and Nokia 501)
Code:
pim = PIM.getInstance();
try {
EventList eventList = (EventList) pim.openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE);
Event event = eventList.createEvent();
// get the current date
Date date = new Date();
// create a reminder starting 1 minute from now
event.addDate(Event.START, Event.ATTR_NONE, date.getTime() + 60000);
// and ending in 2 minutes from now
event.addDate(Event.END, Event.ATTR_NONE, date.getTime() + 120000);
/*
* set the reminder value. 1 = at start time
* 300 = 5 minutes before
* 600 = 10 minutes before
* 900 = 15 minutes before
*/
event.addInt(Event.ALARM, 0, 1);
// import the event to calendar
Event imported = eventList.importEvent(event);
imported.commit();
eventList.close();
} catch (PIMException ex) {
System.out.println(ex.getMessage());
}

Resources