Xamarin Media Plugin Auto start or Timer - c#

In my iOS Xamarin forms project I'm using Xam.Plugin.Media from https://github.com/jamesmontemagno/MediaPlugin as follows
async void Handle_Clicked(object sender, System.EventArgs e)
{
await CrossMedia.Current.Initialize();
var file = await CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions
{
DefaultCamera = CameraDevice.Front,
SaveToAlbum = true,
});
}
Is it possible to automatically start video recording or set a timer for the recording to start?
Ultimately, I'm trying to build a lightweight remotely controllable camera app. So the device whose camera is controlled needs to be able to automatically trigger/start the camera.
Any hint appreciated.

You can't start a video or take a photo without user interaction with Xamarin Media Plugin.
At the following link you can find all StoreVideoOptions where offered
https://github.com/jamesmontemagno/MediaPlugin/blob/master/src/Media.Plugin/Shared/MediaStoreOptions.cs

Related

Find the App which is using front camera in Laptop using UWP/C#

I have to hide the camera preview and off a toggle button when already camera is in use by another application. For this I am using _mediaCapture.Failed += MediaCapture_Failed; event to capture the camera status in side InitializeCameraAsync() method.
But when I minimize and maximize the UWP App very quickly, the event is raising and getting error like 'Camera is in use' for the same App it self.
So is there any way to find which App is using the Camera currently?
So is there any way to find which App is using the Camera currently?
No there is no way to know which app is using the Camera exactly. But in UWP, you could know if the Camera is being used before you start to use the camera.
You can register a handler for the MediaCapture.CaptureDeviceExclusiveControlStatusChanged event, which is raised whenever the exclusive control status of the device changes. Then you could check the MediaCaptureDeviceExclusiveControlStatusChangedEventArgs.Status property to see if the Camera is available now.
Here is the code sample that you could refer to:
private async void _mediaCapture_CaptureDeviceExclusiveControlStatusChanged(MediaCapture sender, MediaCaptureDeviceExclusiveControlStatusChangedEventArgs args)
{
if (args.Status == MediaCaptureDeviceExclusiveControlStatus.SharedReadOnlyAvailable)
{
ShowMessageToUser("The camera preview can't be displayed because another app has exclusive access");
}
else if (args.Status == MediaCaptureDeviceExclusiveControlStatus.ExclusiveControlAvailable && !isPreviewing)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await StartPreviewAsync();
});
}
}

playing media element when lock screen xamarin forms

I am Using Xamarin forms for play some music , when I lock my phone, the audio will stop. how should I Handel ? I do not want music pause
{
MediaElement KeepScreenOn="True" x:FieldModifier="Public" Source="Voice.mp3" AutoPlay="False" ShowsPlaybackControls="True" x:Name="MyMedia"
}
MediaElement is currently experimental, I cannot found this feature play the music when lock screen, but you can use CrossMediaManager, It is support the play the music when lock screen by default.
Just Used a Button to invoke the play method.
<Button Text="play" Clicked="Button_Clicked"></Button>
private async void Button_Clicked(object sender, EventArgs e)
{
await CrossMediaManager.Current.Play("https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3");
}
Note:when add CrossMediaManager.Current.Init(this); in your OnCreate method of MainActivity.cs. Please do not forget the set the Target Framework to Android 9.0 or later.

MediaPlayer Universal Windows App

I started to develop application using xamarin, and one of projects inside my solution is UWP.
I need to play sound there when someone clicked button, I'm using MediaPlayer to achieve my goal, and on windows 10 (desktop) it works fine, but on my Windows Mobile 10 (Lumia 930) it starts with long delay (about 1 second).
Below I provide my code to play audio source:
MediaPlayer _player = BackgroundMediaPlayer.Current;
_player.SetUriSource(new Uri(String.Format("ms-appx:///Assets/Sound/5s.wav", UriKind.Absolute)));
_player.Play();
My Question is:
Is there any other way to play audio in UWP than MediaPlayer?
If you don't have specific reason to use background audio, you can use just media element to play audio in foreground:
<!-- create element in XAML or in code -->
<MediaElement Name="mediaElement" ... />
// Code - set source or reference to stream
MediaElement mediaElement = new MediaElement();
mediaElement.Source = new Uri("msappx:///Media/sound.mp3");
I would also recommend to check with the list of supported codecs.
In more complex scenarios you may want to look at Audio Graph API.
I'm not sure if this is bad practice or not, but I am able to get instant playback if I pre-load the media.
Something like this example in pseudo-code (c# style):
class Foo
{
private MediaPlayer _player;
Foo() //constructor
{
_player = BackgroundMediaPlayer.Current;
_player.AutoPlay = false;
_player.SetUriSource(new Uri(String.Format("ms-appx:///Assets/Sound/5s.wav", UriKind.Absolute)));
}
void ButtonClicked(Object sender, EventArgs event)
{
_player.Play();
}
}

ShareStatusTask doubles Status on WP8.1 Facebook share

I have a simple C# WP8.0 application from where I launch, on a button click, the ShareStatusTask.
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
var task = new ShareStatusTask { Status = "Test message", };
task.Show();
}
When I choose to share on Facebook, Messaging, OneNote etc everything works fine on a WP8 device.
The same application running on a WP8.1 device doubles the Status text only on Facebook share.
I would like to have same behavior as on WP8. What am I missing here?
I ended up using ShareLinkTask instead of ShareStatusTask. Lucky me I needed anyway to add a link to the message.

Set source and play a single mp3 file on each button on windows phone 7

i'm trying to make an application for windows phone 7.1 for schoool. I want to play a sound for each pressed button on my application (just like istantfun button for android) but i have some problem. If i declare on my xaml all the 120 Media Elements my applcation will play only 3/4 sound randomly. I want to make something like this:
private void button1_Click(object sender, RoutedEventArgs e)
{
prova.Source = new Uri("/mp3/call.mp3", UriKind.Relative);
prova.Play();
}
where prova is a single MediaElement declared on the first page of xaml file.
How can i do? Thanks advice
first of all if you want play sound in multi-page app than media element is no good solution.
Besides of it's limitation (single sound at a time) and after considering amount of sound effects maybe you should try using XNA as described here: http://www.dotnetscraps.com/dotnetscraps/post/Play-multiple-sound-files-in-Silverlight-for-Windows-Phone-7.aspx
public void PlaySound(string soundFile)
{
using (var stream = TitleContainer.OpenStream(soundFile))
{
var effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
}
}
With this solution you don't need any XAML elements and thus you can play it app-wide.

Categories