Unable to reference native Android view in Xamarin xaml - c#

I'm using baseflow's MediaManager plugin:
https://github.com/Baseflow/XamarinMediaManager
I need to have multiple video views. From reading the documentation, I know I need to create a video view using native android views in my xaml like this:
<mediamanager.platforms.android.video.VideoView
android:id="#+id/your_videoview"
android:layout_width="match_parent"
android:layout_height="300dp" />
I used the following documentation to try and add native view support:
https://learn.microsoft.com/en-gb/xamarin/xamarin-forms/platform/native-views/xaml
The problem I'm having is that I can't seem to correctly reference 'android:'. I've added the references and I've set [XamlCompilation(XamlCompilationOptions.Skip)] but still I get the squiggly green lines. I've also cleaned/rebuilt/deleted bin/obj files.
Maybe I'm missing something obvious, maybe there is a code wizard out there that can point me in the right direction.

You don’t need to use any of that! You should try the brand new ‘MediaElement’ control on Xamarin forms. It makes adding videos a piece of cake:
<MediaElement Source="https://sec.ch9.ms/ch9/5d93/a1eab4bf-3288-4faf-81c4-294402a85d93/XamarinShow_mid.mp4"
ShowsPlaybackControls="True" />
Even though it’s in preview, it works really smoothly, I watched it in a Kym Philpotts live demo during MS Build 2020. Check out the official docs for it over here: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/mediaelement
Here’s a video to the recorded stream too: https://youtube.com/watch?v=dMR6uaFz0Eg

You can use native views in Forms. Unfortunately, this here is not the case. Your native view needs its own *.axml file in the Android project in order for you to use it.
Looking at the rest of the code that you need for this particular configuration, it should also be written natively (in the Android project) - FindViewById && SetView are all code that needs to be in the Android project.
Unfortunately, in some cases not everything has been prepared for usage in the shared project and occasionally you need to get "your hands dirty" and go "native" in order to configure your code the way you wish.
What you should do it use it as it is being shown in Xamarin.Forms section. Then, you can apply the modifications that are documented in Add Video Player to the UI. You can create a class that inherits from VideoViewRenderer and modify your view there. If you are not familiar with customs renderers, you can read more about them here.

Related

WPF Custom Chrome Window?

i have been trying to make something along the lines of this...
I have looked and looked and only found this article.
I am having trouble integrating this into my application. I just started WPF today, so i am learning. I have downloded the window.Shell dLL. What else do i need? Thanks!
If you are looking for a step-by-step guide on how to add this to your application I can give it a try; I just happened to need a bit of a brush-up for a small app, I liked this and gave it a try - it took me about 45 minutes to apply. Cool stuff actually!
First: Download the source application and extract it to your computer.
In it you will find three subfolders. One with the sample application, one named Microsoft.Windows.Shell, one named CustomChromeLibrary. Copy the latter two to the root folder of your project map, add them to your project map (add existing project) and, from your startup project, reference them.
Now open the Window you want to apply CustomChromeLibrary to. You need to change the root from
<Window>
to
<ccl:CustomChromeWindow>
, this is done by using this code as the document root:
<ccl:CustomChromeWindow
Title="YourWindowTitle" Height="268" Width="733" ResizeMode="CanResize"
x:Class="YourNamespace.YourWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
xmlns:ccl="clr-namespace:CustomChromeLibrary;assembly=CustomChromeLibrary"
xmlns:local="clr-namespace:YourNamespace"
>
Pay attention to the last three lines in the sample. These need to be updated to reference the correct libraries; the last one actually referencing to YOUR namespace.
Next you need to update the source code of your window as this is still a simple Window and you will receive an error from it.
Change this
public partial class YourWindow : Window
to this
public partial class YourWindow : CustomChromeLibrary.CustomChromeWindow
You are already half way there!
Next you just need to create the objects for your window (title bar etc.). This is wonderfully done in the sample project No. 5; I did really just copy it.
Take everything from
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome
...
to here
<!--min/max/close buttons-->
<ccl:CaptionButtons/>
Now you can fill your Window like this
<Grid>
The content of your Window goes here
</Grid>
And close the xaml like this
</Grid>
</ccl:CustomChromeWindow>
Now, if you try to run this you will receive another error. There are still three files missing:
The first one you need is a Microsoft file: CaptionButtonRectToMarginConverter.cs; you will also find it in the sample. Copy it to your project and add it (add existing file).
You need to make one change to it:
namespace YourNamespace
{ ...
instead of the sample's namespace.
Finally you need the two xaml files that create the buttons: GlassButton.xaml and GlassIcon.xaml; they can be found in the "Resources" subfolder (and are referenced as resource dictionaries in the xaml). Copy the whole subfolder to your project and add the two files to your project (add existing file).
Now you should finally be able to run your project.
Let's not forget this: Lots of kudos to gbahns, the author of the original article over at codeplex.com!
There are quite a few implementations you can find for a custom chrome.
Another helper library I've seen to one you linked is
MahApps.Metro
Read section 3. It can be setup with Nuget making it more easier to integrate for someone new.
Also section 3.3 3.4 3.5 talk about customising and expanding the MetroWindow control which gives you a custom chrome and also allows adding controls to the chrome title bar
Over in this stack overflow question:
How can I add a button to the WPF caption bar while using custom window chrome?
I was asking about how to insert buttons into the title bar of my Custom Window Chrome window. The xaml example might be enough to help you get going.
Other than that, I'm not sure what you are looking for.
Edit: The button style I have in that other post is a fairly simplistic button, but you should be able to replace it with any styling that you want.

Unable to get WPF Sound Visualization Library working

I've recently begun work on an audio application using C#.NET. I've begun some basic implementation of the NAudio library which I intend to use throughout the project. While looking at NAudio's documentation on CodePlex I found a link to the WPF Sound Visualization Library, I was attracted by one of its features in particular which I knew I would require in my app.
So I downloaded and added it to my project References.
I've copied how it is referenced within a window's XAML document, like so:
xmlns:svl="clr-namespace:WPFSoundVisualizationLib;assembly=WPFSoundVisualizationLib"
and then tried to add a control within the library using:
<svl:WaveformTimeline x:Name="testWaveformTimeline"/>
The problem is that the designer/XMAL editor claims: "svl:WaveformTimeline" does not exist in namespace "clr-namespace:WPFSoundVisualizationLib;assembly=WPFSoundVisualizationLib".
Now I know that it does exist. I can make reference to the WaveformTimeline object in the class file, and the object shows up in Visual Studio's Object Browser.
I'm not at all sure why this is the case. If anyone knows any possible solutions to this, or things I should check any help would be appreciated.
I had the same issue and I just found the solution:
By right-clicking on the WPFSoundVisualizationLib .dll I had to 'unblock' the file which had been marked as 'unsafe' by windows because the file were coming from a WebSite. Weird but it was obviously the reason I couldn't use the WaveformTimeLine in my project. A bit late but maybe still worths to post it.
More info here: https://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx

Android and iOS cross-platform string resources (MonoTouch & MonoDroid)

I'm busy with a cross-platform mobile app using the Xamarin mono libraries and I ran into the following situation...
I've got a bunch of string resources in my monodroid project (strings.xml) that are being used by my layouts and my C# code.
What I would like to to is to move these string resources to a file in a shared project so that both iOS, Android and Windows phone will be able to use them.
What is the best way to achieve this?
*Currently i'm using a Resource.resx file that contains the non-UI strings. And then I have the strings.xml file in the android(monodroid) project to cater for the UI resource strings.
Keep the following in mind:
The same file must be used by all the platforms.
I need the android layouts to also use the same resources. (which currently is the strings.xml file)
It should preferably be one file.
Any opinions?
There are (at least) a couple of 'standard' libraries/tools you could look at:
Rdio's Vernacular tool looks to help with this problem using a GetText layer - https://github.com/rdio/vernacular
MvvmCross uses JSON files to share text (see Localising text in MvvmCross ViewModels)
Both of those are open source - you should be able to make your own design-time or run-time tools out from those.
Another option would be to use a generator to generate the appropriate resources at build time. For simplicity, I decided to create a Resource Migrator that I run with every build.
Essentially, I take everything in my PCL's *.resx files, and generate Android or iOS resources before building the app. This is a similar approach to combining/minifying CSS/JS in a web application during build time... it reduces performance overhead at runtime.

Winform embeded XNA contentmanager only recognize XNB

I'm writing a MapEditor in winform with embeded XNA.
And my biggest problem is whenever I try to load any file with the ContentManager, it only reads .XNB files.
I wanted to read an effect file like this:
effect = contentManager.Load<Effect>("Effect2");
But then I get the error that "Effect2.xnb doesn't exists".
And if I add "Effect2.fx" it still give me error with the message "Effect2.fx.xnb doesn't exists" :\
I have no idea what to do.
I saw a solution by set the content properties. But I cannot set those properties in this case,because it's a winform application.
Does anyone have a great idea or anything?
Edit!
Solution found!
I implemented the ContentBuilder from this example with writing a few helper methods for dynamic loading: http://create.msdn.com/en-US/education/catalog/sample/winforms_series_2
You'll have to add an XNA Content project, and include your content in that project. All of those files will be compiled/processed into individual XNB files, which you'll be able to load. Just make sure to reference that project in your WinForms project.
The same rules apply for a Game project: It still needs an accompanying Content project.
EDIT:
Ahh, right... you want to load them dynamically. For that, you'll need to ensure that any computer that tries to use your map editor will have the XNA development framework installed. Then you'll need to process the files manually before loading them with the ContentManager... not entirely sure how to do this.
EDIT:
Take a look at this post for more information about loading unprocessed content at runtime: How do I load a texture in XNA at runtime?

C# Vlc.DotNet Libraries - Null reference exception

Recently stumbled upon this post whilst trying to decide on the best way of getting a VLC player into C#.
Does VLC media player have a C# interface?
I downloaded the dll files and imported them into my project, but then realised I had no real idea of how to use them. Has anyone got a Windows Forms example of this code that works? The code have tried is shown below -
Vlc.DotNet.Core.Medias.MediaBase media = new
Vlc.DotNet.Core.Medias.PathMedia(#"C:\Users\...\SampleVideos\Wildlife.wmv");
Vlc.DotNet.Forms.VlcControl vlcControl1 = new Vlc.DotNet.Forms.VlcControl();
vlcControl1.Play(media);
I am also using the code in this link in the main program.cs of my project.
http://vlcdotnet.codeplex.com/wikipage?title=Forms
The current problem I experience is that upon starting the project it throws a NullReferenceException when it gets to ->
vlcControl1.Play(media)
The problem seems to be with the vlcControl but I am unsure why. The documentation seems to rather thin and I couldn't find any working examples on the codeplex site. If anyone has a working forms example or knows what I might have missed please let me know!
Here is the call stack present when the error occurs ->
RTSPViewer_Test.exe!RTSPViewer_Test.Form1.Form1_Load(object sender,
System.EventArgs e) Line 31 + 0xd bytes C#
RTSPViewer_Test.exe!RTSPViewer_Test.Program.Main() Line 30 + 0x1d bytes C#
When debugging it appears that the Media and Medias attribute of the VLC control are both null. When trying to set the Media of the control to the media object created above a
NullReferenceException
Checking the VLC control object Media does indeed equal null, but I am not sure why it hasn't been initialised properly.
I was unable to get the program to work using the latest version of the Vlc.dotnet libraries but instead used the alpha 2 version which was posted by Raj. I used VLC version 1.1.5 with this library to get the basic example to function properly. My end objective was to stream from an rtsp device, however this library does not appear to support this functionality yet.
For anyone looking to use a good C# wrapper for using VLC then this is a great example -
http://www.codeproject.com/Articles/109639/nVLC
Used the library files from VLC 1.1.1 with this project and works fine. Supports pretty much all the features that you would usually use in VLC but gives you much more control over what you use them for.
Many of the issues that arise when using these DLL wrappers arose from incorrect versions of the source DLL files. The VLC libraries are only 32 bit at this time, so you need to make sure to compile using x86 mode otherwise the libvlc.dll will not load properly and the application will crash. Using the above example you must also make sure that the libvlc.dll, libvlccore.dll and the plugins folder are included in the build folder.

Categories

Resources