For a xamarin project, I am using CrossMediaManager from https://github.com/Baseflow/XamarinMediaManager , it works fine for playing video and audio. I have a video view on the form which displays video for a video url, but for Audio it remains blank and black.
How can I set it source to some image file, so it looks bit better. Setting Source property doesnt work. The image file does exists in both the plateforms as we are using it for some reasons also.
I tried doing using code.
videoPlayer.Source = "SomeImageFile";
Thanks
You could use a image to cover the VideoView when it play the audio.
Xaml:
<StackLayout>
<Grid>
<mm:VideoView x:Name="video" ShowControls="True" />
<Image Source="pink.jpg" />
</Grid>
<Button Clicked="BtnPlayLocal_Clicked" Text="play local video" />
</StackLayout>
Code behind:
private void BtnPlayLocal_Clicked(object sender, EventArgs e)
{
//audio
CrossMediaManager.Current.Play("https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3");
// video
//http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4
}
Related
Is there any option to play lottie starting at the end, playing backwards to the start of the animation in xamarin? From code behind in c#
<lottie:AnimationView x:Name="lottie" AutoPlay="False" Animation="heartreaction.json" />
Clicked
private void super_Clicked(object sender, EventArgs e)
{
lottie.PlayAnimation();
//Instead play it backwards
}
If you use SKLottieView, you could set RepeatMode="Reverse" to make it. You could add Skiasharp.Extended.UI.Forms Nuget first.
The following code is an example:
<skia:SKLottieView
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
x:Name="myanimatedview"
Source="dotnetbot.json"
HeightRequest="300"
WidthRequest="300"
RepeatCount="-1"
IsAnimationEnabled="True"
RepeatMode="Reverse"/>
Or set it in code behind cs file:
myanimatedview.RepeatMode = SKLottieRepeatMode.Reverse;
Hope it works for you.
I am using MediaManager Plugin with latest version to play a video. everything works fine when i run application in debug mode, but when i create a package for window, video is not showing only voice is heard.
I am using below Package
Plugin.MediaManager.Forms
This is My XAML page
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Digi_Sign.Views.MediaScreen"
xmlns:forms="clr-namespace:MediaManager.Forms;assembly=MediaManager.Forms"
BackgroundColor="Black">
<ContentPage.Content>
<Grid x:Name="stkLayout" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" BackgroundColor="Black">
<forms:VideoView VideoAspect="AspectFill" x:Name="videoPlayer" ShowControls="False" />
</Grid>
</ContentPage.Content>
</ContentPage>
CS Page
CrossMediaManager.Current.Play(fileName);
No Errors Found in package error log, as i mentioned everything works fine when it is debug mode, but not working in release mode
Basically there is no way to initialize renderer for video in native code for xamrin.UWP, so we need to manually load render assembly in initialize it in App.xaml.cs of UWP platform
Below is my code where i have load assembly files inside OnLaunched() and replace existing Xamarin.Forms.Forms.Init()
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Windows.UI.Xaml.Controls.Frame rootFrame = Window.Current.Content as Windows.UI.Xaml.Controls.Frame;
if (rootFrame == null)
{
rootFrame = new Windows.UI.Xaml.Controls.Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
List<Assembly> assembliesToAdd = new List<Assembly>();
assembliesToAdd.Add(typeof(VideoViewRenderer).GetTypeInfo().Assembly);
Xamarin.Forms.Forms.Init(e, assembliesToAdd);
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
Window.Current.Activate();
}
for more details, here is the link. where you can find more explaination.
https://forums.xamarin.com/discussion/119451/crossmedia-works-in-debug-but-not-in-release-for-uwp-error-msg-about-onecore
Most likely from the behavior you are describing (and looking at your code), it sounds like it's because the Video is not being run on the UI thread, and this causes the app to play the audio but not the video. So change it to the following:
Device.BeginInvokeOnMainThread(() => { CrossMediaManager.Current.Play(fileName); });
I would like to display an icon as a placeholder when I clicked it will capture a picture and change the icon for the stored picture (capture a picture process is completed already . all I need is to trigger and display the results (picture file ) and replace the placeholder (Add.png) icon for (capture file image ) using XAMARIN FORMS . any help ? thanks )
XAML
<Image x:Name="Photo2" Source="Add.png" Grid.Row="1" Grid.Column="1">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnPhoto2_Clicked" />
</Image.GestureRecognizers>
</Image>
XAML.CS
async void OnPhoto2_Clicked(object sender, EventArgs args)
{
await App.Navigator.PushAsync(new TEST()); //when clicked navigate to a new page that store the gallery of images
}
Can we play 2 videos simultaneously in windows phone 7 application.
I am using 2 media elements in 1 xaml page. But only one of the videos is getting displayed. How can I play videos. Please suggest some pointers.
You Can use only one MediaElement on a page. please refer MediaElement Design Guidelines First.
The reason you are seeing on video is because when we use MediaElement, all other playing audio video are stops.
The answer how can you play two videos using MediaElement or another option is CompositionTarget.Rendering Event.
CompositionTarget.Rendering actually renders a frame.
For details visit here.
Code in XAML
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel>
<MediaElement Name="ME1" Source="/Images/oceansclip1.mp4" Stretch="Fill" AutoPlay="False" VerticalAlignment="Top" Height="250"/>
<MediaElement Name="ME2" Source="/Images/oceansclip2.mp4" Stretch="Fill" AutoPlay="False" VerticalAlignment="Top" Margin="0,10" Height="250"/>
<Button Content="Play" Click="Button_Click_1"/>
</StackPanel>
</Grid>
Code behind XAML
private void Button_Click_1(object sender, RoutedEventArgs e)
{
CompositionTarget.Rendering += CompositionTarget_Rendering1;
}
private void CompositionTarget_Rendering1(object sender, EventArgs e)
{
mediaElement1.Play();
mediaElement2.Play();
}
But CompositionTarget.Rendering do not guarantee time between the calls, so you may get frames running faster or slower.
I want to play an audio of an image whenever click on it .If we click on another image that sound will play in that way we want write the logic.
If you're binding to an object that has the image uri and audio clip uri:
<Image Source="{Binding ImagePath}" Tag="{Binding AudioPath} MouseLeftButtonDown="img_MouseLeftButtonDown" />
then in the event handler
void img_MouseLeftButtonDown(object sender,MouseButtonEventArgs e)
{
Image img = sender as Image;
if (img != null)
mePlayer.Source = img.Tag as Uri;
}
i dont recommend mediaElement for more than one audio item ..it has weird effects ...use something like:
Stream stream = TitleContainer.OpenStream(#"Audio/buzzer.wav");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
using the xna framework ....