Can't see video player controls using `libvlcsharp` - xamarin.forms

I'm using libvlcsharp to play video, in iOS controls are showing but in android there are white boxes instead of controls. Kindly help
Here is XAML
<vlc:MediaPlayerElement x:Name="myvideo" HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand" HeightRequest="200"/>
Code Behind
LibVLC _libVLC;
public TestPage()
{
InitializeComponent();
Core.Initialize();
_libVLC = new LibVLC();
var media = new Media(_libVLC, "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", FromType.FromLocation);
myvideo.MediaPlayer = new MediaPlayer(media) { EnableHardwareDecoding = true};
myvideo.MediaPlayer.Play();
}

Related

Dynamically add Icons to titlebar Maui

Im creating an App where I want have multiple icons in my titlebar (they should be clickable). One Icon should be on the Left of the title text like so (this icon is static and will not change):
The other Icons should be on the right (these icons should be dynamic, as they will be used to alert the user if anything important happens):
I'm using a simple shell, so no Navigationpage, thus I don't think <NavigationPage.Titleview> can be used in this case. Is there any way to achieve something like this in Maui?
You can use the shell title view as stated in this answer, it is pointing to Xamarin documentation but it is also valid for MAUI.
In your case you will have something like this inside your AppShell.xaml :
<Shell.TitleView>
<Grid ColumnDefinitions="auto,*,auto">
<Label Text="Title" BackgroundColor="Red"></Label>
<HorizontalStackLayout Grid.Column="2">
<Label Text="Icon" BackgroundColor="Red"></Label>
</HorizontalStackLayout>
</Grid>
</Shell.TitleView>
Which look like this (very trendy design) :
How to update the icons can be done by data binding or creating directly the object from C# :
<HorizontalStackLayout Grid.Column="2" x:Name="IconsContainer">
<Label Text="Icon" BackgroundColor="Red" IsVisible="{Binding Icon1Visible}"></Label>
</HorizontalStackLayout>
And in the C# :
public partial class AppShell : Shell
{
public bool Icon1Visible { get; set; } = false;
public AppShell()
{
InitializeComponent();
// An object containing the binding data
BindingContext = this;
// Directly create a new icon
AddIcon();
// Show an icon through binding
ShowIcon();
}
public void ShowIcon()
{
Icon1Visible = true;
}
public void AddIcon()
{
var icon = new Label();
icon.Text = "And another one";
IconsContainer.Children.Add(icon);
}
}
To get whenever you want to update the icons I would go with dependency injection and either pass directly a view model to bind the icons on or using events.

Xamarin - get control dimensions

I really don't know how to get control dimensions in Xamarin Forms. I thought it would be as easy as:
View control = GetControlSomehow();
var bounds = control.Bounds;
But View.Bounds returns different things depending on wether the control is inside a grid or not; or wether the main layout is AbsoluteLayout or some other one.
For example if I do something like:
<AbsoluteLayout>
<Button AbsoluteLayout.LayoutBounds="200,200" x:Name="btn" Text="Btn"/>
</AbsoluteLayout>
then I am not able to read actual height or width of that button. Although MSDN says that Height & Width properties should return these values.
I tried even:
var width = ctrl.Width;
or
var width = ctrl.GetValue(WidthProperty);
But really non of these worked. I always get -1
So how can I get the control dimensions that could be reliable?
Complete example showing how to pass button itself, using data binding.
AbsoluteLayoutPage.xaml:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestBugs.AbsoluteLayoutPage">
<ContentPage.Content>
<AbsoluteLayout>
<Button AbsoluteLayout.LayoutBounds="200,200" x:Name="btn" Text="Btn"
Command="{Binding ButtonCommand}" CommandParameter="{x:Reference btn}"/>
</AbsoluteLayout>
</ContentPage.Content>
</ContentPage>
AbsoluteLayoutPage.xaml.cs:
using System.Diagnostics;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace TestBugs
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class AbsoluteLayoutPage : ContentPage
{
public AbsoluteLayoutPage()
{
ButtonCommand = new Command(ButtonClick);
InitializeComponent();
BindingContext = this;
}
private void ButtonClick(object ob)
{
var button = ob as View;
var bounds = btn.Bounds;
var width = btn.Width;
var height = btn.Height;
Debug.WriteLine($"--- ButtonClick {bounds}, ({width},{height})---");
}
public Command ButtonCommand { get; set; }
}
}
When click button, in VS Output pane:
[0:] --- ButtonClick {X=200 Y=200 Width=88 Height=48}, (88,48)---
this works for me
<Button Text="Click" Clicked="Clicked" />
public void Clicked(object sender, EventArgs a)
{
var btn = (Button)sender;
var w = btn.Width;
var h = btn.Height;
DisplayAlert("Dimesions", $"{w}x{h}","OK");
}
Sorry guys, my bad.
I was testing it on two pages - the real one and the test one. The test page is built in a different way and I confirm that the problem was in time when I retrieved these values. Control wasn't painted yet.
So I am really sorry to bother you and thank you all for investing your time into this.

Unable to select text in Xamarin.Forms Editor control or custom Borderless Editor using renderer

I've implemented Borderless Editor in my Xamarin.Forms application using Custom EditorRenderer. But I'm facing an issue that the editor text is not selectable at all in both cases, neither in Forms editor control nor in Rendered native editor control. My app has the functionality to let user copy paste the text in the editor while typing, like in any other text editing app. This is a basic feature in most of the apps and is by default there. But it's not working in my app. I've tried enabling it through
Control.SetTextIsSelectable(true);
but still it's not working. I've tried other things too, like:
Control.CustomSelectionActionModeCallback = new
CustomSelectionActionModeCallback();
Control.CustomInsertionActionModeCallback = new CustomInsertionActionModeCallback();
But nothing is working at all and text is not getting selected even a single word. Does anyone has any idea about this issue? How can I make the text selectable and allow default copy paste feature in custom editor?
Here's my code in Xaml:
<renderer:BorderlessEditor
Grid.Row="1"
x:Name="UserTextEditorAndroid"
BackgroundColor="{StaticResource WhiteColor}"
HeightRequest="350"
Margin="20,2"
MaxLength="1024"
IsReadOnly="{Binding Source={x:Reference LongTextTemplate}, Path=Editable, Converter={StaticResource InverseBool}}" />
And the custom render code is:
public class BorderlessEditorRenderer : EditorRenderer
{
public BorderlessEditorRenderer()
{
}
public static void Init() { }
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
Control.Background = null;
var layoutParams = new MarginLayoutParams(Control.LayoutParameters);
layoutParams.SetMargins(0, 0, 0, 0);
LayoutParameters = layoutParams;
Control.LayoutParameters = layoutParams;
Control.SetPadding(0, 0, 0, 0);
SetPadding(0, 0, 0, 0);
Control.SetTextIsSelectable(true);
Control.VerticalScrollBarEnabled = false;
}
}
}
Even if I use Xamarin.Forms own editor in Xaml instead of custom renderer then also it doesn't work at all. The text is still un-selectable.
I am having the same problem - but I'm not using Telerik. I'm running VS 2019 on Win 10. This is easy to repro ...
Create a new "Mobile App (Xamarin Forms)" and simply add an Editor to the MainPage.xaml file. I also put the Editor inside a ScrollView for kicks. The code below only shows a few words of text placed in the Editor, but I actually used a long paragraph from the Microsoft docs. I left that out below so as to simplify code presentation ... and avoid a mess!
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Editor_Test.MainPage">
<StackLayout>
<!-- Place new controls here -->
<ScrollView>
<Editor Text="Visual Studio makes it easier ..."
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" />
</ScrollView>
</StackLayout>
</ContentPage>
I get normal behavior:
Because of the ScrollView, I can scroll the text with a finger (mouse) drag
A long press (click) selects the word pressed
A double tap (click) selects the word tapped
I get different results if I change 1 line of code in the App ctor, in App.xaml.cs, to instantiate the MainPage with a NavigationPage, like so:
public App()
{
InitializeComponent();
//MainPage = new MainPage();
MainPage = new NavigationPage(new MainPage());
}
Now the behavior changes:
A long press (click) has no effect (no selection)
A double tap (click) has no effect (no selection)
In fact there is no way at all that I can see to select text in the Editor. I don't know why this happens ... but it does. It drove me a bit mad until I realized what was causing it.
I'm using:
Xamarin Forms 4.5.0.495
Xamarin Essentials 1.3.1
Building for Android 9 (Pie)
I'm new to Android/Xamarin ... so my question is, how best to implement my own simple page navigation - ie, without using Xamarin's NavigationPage? I have a simple 3 page app I'd like to make some progress with!

MasterDetailPage SlideOut and and Slide In Button not showing in Master detail .To Slide right and slide left out with Button

Here is The Code To setting Title and Image butt ..Title Showing button Slider button not Showing
masterPage = new MasterDetailPage()
{
BackgroundColor = Color.Transparent,
Master = BuildMenuPage(),
Title = AppResources.AppNameWithPortal,
IconImageSource =new FileImageSource {File= "slideout.png" }
};
I have also try masterPage.IconImageSource ="slideout.png";
still not working
I want this Result
Try to assign icon to master page:
Xamarin forms MasterDetailPage Menu icon not shown on iOS
var masterDetailpage = new MasterDetailPage {
Master = new Page { Title = "Sample", Icon = "menuIcon.png"},
Detail = new NavigationPage(new Page())
};
I think the screenshot you shared in your question is a screenshot of Universal Windows Platform (UWP). MasterDetailPage has different behaviors in different platform. You can check the document here.
If you want the result in the screenshot, you can customize your masterPage and add event to the slideout button, something like this:
<StackLayout>
<StackLayout>
<ImageButton Source="slideout.png"></ImageButton>
<Label Text="title">
</StackLayout>
<ListView x:Name="listView" x:FieldModifier="public">
...
</ListView>
</StackLayout>
The icon or fileImageSoure you set in the Page will be displayed if supported by the platform under certain circumstances, such as when a NavigationPage is displaying a ContentPage.
Usually, detailPage has a NavigationPage and the icon and title will be displayed there in Android.
You can check the sample here to see the default behavior of MasterDetailPage in Android.

Calendar Date Picker In Xamarin Forms UWP

How to create a calendar type date picker in Xamarin forms UWP app.
So far I have tried this:
<Image Grid.Row="3" Grid.Column="1" Source="Images/datePicker.png" WidthRequest="20" HeightRequest="20" Margin="-40,0,40,0" HorizontalOptions="End">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding OnSelectDOBCommand}"/>
</Image.GestureRecognizers>
</Image>
public void OnSelectDOB(object obj)
{
dateOfBuildDatePicker = UserDialogs.Instance.DatePrompt(new DatePromptConfig { MaximumDate = DateTime.Today, OnAction = (result) => SetDateOfBirth(result), IsCancellable = true });
}
But this displays the date picker control on top left corner of the screen.
Is there a way to customize it so that it should display the date picker right next to the field where I click or is there any other control which can help me achieve this functionality.(Below image is the behavior that I am expecting)
Any help is appreciated]1
If you want to consume a special control on UWP platform, you can try custom renderer.
Firstly, create a custom control:
public class CustomDatePicker : DatePicker
{
}
Then make a custom renderer on UWP:
[assembly: ExportRenderer(typeof(CustomDatePicker), typeof(CustomDatePickerRenderer))]
namespace Demo.UWP
{
public class CustomDatePickerRenderer : ViewRenderer<DatePicker, Windows.UI.Xaml.Controls.CalendarDatePicker>
{
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
if (Control == null)
{
Windows.UI.Xaml.Controls.CalendarDatePicker datePicker = new Windows.UI.Xaml.Controls.CalendarDatePicker();
SetNativeControl(datePicker);
}
}
}
}
At last, use it on your forms project:
<StackLayout>
<local:CustomDatePicker HorizontalOptions="Start"/>
</StackLayout>
Alternatively, you can try native view: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/platform/native-views/
date value is always set to the current date even you selected a data. how to resolve this?
Changing the date value requires working with the date change events. See my working solution here:
https://stackoverflow.com/a/60449912/9523062

Resources