Xamarin ios song does not always play on speaker - c#

I am user Xamarin fomrs text to speech api click here to see
I have manage to implemented it on my app but some time the song play on phone speaker and some speak on earphone after record the song
Question:
How to make the song always play on phone's speaker
Here is the code :
var config = SpeechConfig.FromSubscription("xxxx", "xxxx");
config.SpeechSynthesisVoiceName = MicosoftTranslater.MySpeakerlanguagesList( "fr-FR");
var synthesizer = new SpeechSynthesizer(config);
await synthesizer.SpeakTextAsync("I am playing from phone speaker");
Thanks for your help

The key is calling the SetCategory with the appropriate AVAudioSessionCategory and setting the session to active.
Like:
var session = AVAudioSession.SharedInstance();
session.SetCategory(AVAudioSessionCategory.Playback);
session.SetActive(true);
You could use DependencyService to set it in your ios project.You could refer to https://learn.microsoft.com/en-us/answers/questions/320860/isimpleaudioplayer-issues-on-ios-and-with-speechre.html.

Related

How to get current microphone state within a call (muted / unmuted)?

I've installed the Microsoft Teams(work or school / version 1.6.00.1381 ) app on Win 11.
I'd like to detect whether microphone within a call is muted or not.
I found this https://stackoverflow.com/questions/67569705/get-current-call-status-of-microsoft-teams ,
someone said : Currently there is no api to get the current microphone state within a call.
Now I have a workaround to know the microphone status on Teams by NAudio
step1: set mute/unmute
using var deviceEnumerator = new MMDeviceEnumerator();
var devices = deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active);
_isMicMuted = !_isMicMuted;
foreach (var device in devices)
{
device.AudioEndpointVolume.Mute = _isMicMuted;
}
step2: get microphone status
devices.Any(x => x.AudioEndpointVolume.Mute);
This way will fail because when user manually press unmute/mute mic button,
it didn't change device.AudioEndpointVolume.Mute value.
enter image description here
is there any other way do this?

How to stop music on Xamarin forms app when leaving an app and play it when back

I am using Xamarin forms would like to know how to stop/pause music when leave the app. and Play the music when I back on the app
I use a function in my ConttentPage to read and play a music :
ISimpleAudioPlayer AudioPlayerSucces;
void InitMyAudio()
{
string filenamesuccess = "Lea.MyAudios.Question.success_song.wav";
using (Stream streamSuccess = GetType().GetTypeInfo().Assembly.GetManifestResourceStream(filenamesuccess))
{
AudioPlayerSucces = CrossSimpleAudioPlayer.CreateSimpleAudioPlayer();
AudioPlayerSucces.Load(streamSuccess);
}
AudioPlayerSucces.Play();
}
Thanks for your help

Playing an HDHomeRun stream on a Tizen.NET Xamarin App

I'm trying to play a HDHomeRun Connect Video source from a url in the following format: http://x.x.x.x:xxxx/auto/v4.1. This video source is an MPEG2 video encoding and AC3 audio encoding.
I've tried using the Samsung Tizen.TV .NET sample with the following source but the video never plays.
_player = new Tizen.Multimedia.Player();
var mediaSource = new Multimedia.MediaUriSource(uri);
_player.SetSource(mediaSource);
var display = new Multimedia.Display(Window.Instance);
_player.Display = display;
await _player.PrepareAsync();
The player state gets stuck in preparing, and the await _player.PrepareAsync() call never finishes. It is worth noting that I'm using the Tizen Samsung TV Emulator. Do I need to transcode the stream from the HDHomeRun to be playable? Are there any other measures I might be missing for the Video to play?
Ultimately, the Display property of the player wasn't being set correctly. The property that worked for me (found from investigating the JuvoPlayer code was this:
var display = new Multimedia.Display(((FormsApplication)Forms.Context).MainWindow);
_player.Display = display;
When you are to develop a Tizen .NET application, please be aware of which UI framework your project is targetted for among 3 different types: Xamarin.Forms, (pure) ElmSharp, and Tizen.NUI.
Unless your project is based on the Tizen.NUI framework, you shouldn't use Tizen.NUI.Window.Instance and types in Tizen.NUI namespace in any case. Instead, you will have to use types of ElmSharp or Xamarin.Forms.Platform.Tizen namespace for platform-specific code in your application.
Since the internal implementation of Xamarin.Forms for Tizen is based on ElmSharp, FormsApplication.MainWindow will return a ElmSharp.Window instance which can be used to instantiate a Tizen.Multimedia.Display object. That's why the code in your answer worked.

How can i create Flashlight app in uwp C#

I have Lumia 830 and i've tried to create flashlight app in UWP C#. my device Flashlight works great but i don't know why i can't create my own app turn on / off Torch of my phone.
I use Lamp class :
var lamp = await Lamp.GetDefaultAsync();
if (lamp == null)
{
ShowErrorMessage("No Lamp device found");
return;
}
lamp.IsEnabled = true;
when run this code on my phone "lamp" is null and it couldn't find my FlashLED. I've got this code from MSDN.Microsoft.com and thay said
If the returned object is null, the Lamp API is unsupported on the
device. Some devices may not support the Lamp API even if there is a
lamp physically present on the device.
This class doesn't work on my Lumia 830 i don't kno why? :(
also i use this code :
var mediaDev = new MediaCapture();
await mediaDev.InitializeAsync();
var videoDev = mediaDev.VideoDeviceController;
var tc = videoDev.TorchControl;
if (tc.Supported)
{
// But wait, for this to work with Blue camera drivers, we have to Start a recording session
// Create video encoding profile as MP4
var videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);
// Start Video Recording
var videoStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync("tempVideo.mp4", CreationCollisionOption.GenerateUniqueName);
await mediaDev.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile);
// Turn on Torch
mediaDev.VideoDeviceController.TorchControl.Enabled = true;
}
this code works and my FlashLED turn on but it record video and it take's user SD Card memory.
please help me if you know there is best way to turn on/off Torch or FlashLED.
thanks in advance
Hussein Habibi Juybari
The Lamp API is designed for Windows 10 devices only and you can only use it on devices which support the API. Currently supported devices are 950/950XL, 650, and 550. Older devices will not be updated to support this API. You should fall back to the Windows 8.1 method of turning on flash when you detect that the lamp device is not available on older devices.
From: https://wpdev.uservoice.com/forums/110705/suggestions/15846967
Please test default sample named LampDevice (cf. https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/LampDevice). Do you have the same behavior ? I just tested on Lumia 930 it works fine. No Lumia 830 to test it.

MediaPlayerLauncher on WP7 - how to resume previously playing media?

I'm using a MediaPlayerLauncher to show movietrailers in my WP7 application, like this:
MediaPlayerLauncher mpl = new MediaPlayerLauncher();
mpl.Media = new Uri(trailerUrl, UriKind.Absolute);
mpl.Controls = MediaPlaybackControls.All;
mpl.Show();
This works just fine, except one thing: if the user is already listening to music in the background, and launch a trailer, the music is not resumed after the trailer is done playing (or if the user closes the video).
Does anyone know how i can resume the previously playing music/media, if even possible?
Local media playing through XNA or a 'background audio agent'?
When you play media in WP7 / WP8, the OS audio context is taken, and the original context is lost. If the audio was launched from an external application, then you cannot resume at all. If the previous media was launched from within your application, then you could store the meta-data and re-play once your trailer is finished. The media would, of course, then begin playing from the start, rather than where the user left off. Unfortunately XNA does not allow you to seek within a given piece of media; however you can seek within an 'audio agent' instance of 'BackgroundAudioPlayer' by setting player.Position. It's also worth looking at the MediaHistory API:
var nowPlaying = Microsoft.Devices.MediaHistory.Instance.NowPlaying;
Figured it out. Calling MediaPlayer.Resume() right after show() solves the issue:
mpl.Media = new Uri(trailerurl, UriKind.Absolute);
mpl.Controls = MediaPlaybackControls.All;
mpl.Show();
MediaPlayer.Resume();
However, i would still like to know how to resume radio and spotify!

Categories