how to Play .flv files in WPF? - wpf

How to Play .flv files in WPF? please anyone help me out.

// Create the interop host control.
var host = new WindowsFormsHost();
// Create the ActiveX control.
var axShockwaveFlash = new AxShockwaveFlash();
// Assign the ActiveX control as the host control's child.
host.Child = axShockwaveFlash;
// Add the interop host control to the Grid
// control's collection of child controls.
this.MainGrid.Children.Add(host);
axShockwaveFlash.Location = new System.Drawing.Point(0, 0);
axShockwaveFlash.LoadMovie(0, #"C:\player.swf");
axShockwaveFlash.SetVariable("quality", "Low");
axShockwaveFlash.ScaleMode = 0;
axShockwaveFlash.AllowScriptAccess = "always";
//axShockwaveFlash.FlashVars = #"file=C:\barsandtone.flv" +
//&autostart=true&fullscreen=true&controlbar=none&repeat=" +
//"always&stretching=fill";
axShockwaveFlash.CallFunction("<invoke name=\"loadFLV\" " +
"returntype=\"xml\"><arguments><string>barsandtone.flv</string>" +
"</arguments></invoke>");
axShockwaveFlash.Play();
Reference:
Hosting Flash movie in a WPF project
Hosting Flash Movie in WPF (Part 2): Some ‘Strictly Microsoft Technology Please’ options

If you want to use DirectShow, you must use WPFMediaKit.
With http://www.free-codecs.com/download/K_lite_codec_pack.htm it will be ok.
Max #GoTactile

If thats using DirectShow then you probably just need a codec installed:
http://www.free-codecs.com/download/K_lite_codec_pack.htm

Related

Is there a Geopoint class available for Winforms (or an Analogue thereof)?

In my UWP app, I use a Geopoint class:
using Windows.Devices.Geolocation;
. . .
List<Geopoint> locations;
In a Winforms app, this is not available - Geopoint is not recognized. Is there an analogous class available for Winforms apps?
The same is true for the BasicGeoposition object - not recognized.
UPDATE
I want the GeoPoint and BasicGeoposition classes so I can do things like this:
BasicGeoposition location = new BasicGeoposition();
location.Latitude = 36.59894360222391; // Monterey == 36.6002° N
location.Longitude = -121.8616426604813; // Monterey == 121.8947° W (West is negative)
Geopoint geop = new Geopoint(location);
await map.TrySetSceneAsync(MapScene.CreateFromLocation(geop));
cmbxZoomLevels.SelectedIndex = Convert.ToInt32(map.ZoomLevel - 1);
map.Style = MapStyle.Aerial3DWithRoads;
UPDATE 2
I tried the code provided in the answer:
this.UserControl1.myMap.AnimationLevel = AnimationLevel.Full;
this.userControl11.myMap.Loaded += MyMap_Loaded;
...but it won't compile. I don't have a UserControl11 (which is what the answer's code has), but I do have a UserControl1, yet it is not recognized:
This is the XAML in question (Bing Maps key obfuscated):
<UserControl x:Class="MyMaps.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF">
<Grid>
<m:Map CredentialsProvider="Gr8GooglyMoogly" x:Name="myMap" />
</Grid>
</UserControl>
To set the view of the Bing Maps WPF control, you can use SetView method. The method have different overloads, for example you can pass a Location(which you create based on the latitude and longitude of your desired location) and a zoom-level to the method like this:
var location = new Location(47.604, -122.329);
this.userControl11.myMap.SetView(location, 12);
Same can be achieved by setting Center and ZoomLevel.
Download or Clone the example
You can download or close the working example from here:
Clone r-aghaei/WinFormsWpfBingMaps
Download master.zip
Step by Step Example - Zoom into Seattle as initial view
Follow instructions in this post to create a Windows Forms project which uses WPF Bing Maps Control.
Handle the Load event of the Form and use the following code:
private void Form1_Load(object sender, EventArgs e)
{
this.userControl11.myMap.AnimationLevel = AnimationLevel.Full;
this.userControl11.myMap.Loaded += MyMap_Loaded;
}
private void MyMap_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
var location = new Location(47.604, -122.329);
this.userControl11.myMap.SetView(location, 12);
}
Make sure you use using Microsoft.Maps.MapControl.WPF;.
As a result, the map zooms in Seattle as center location:
More information:
You may want to take a look at the following links for more information:
How can I add a Bing Maps Component to my C# Winforms app?
Bing Maps WPF Control
Developing with the Bing Maps WPF Control
Bing Maps WPF Control API Reference
For those who are looking to use Windows Community Toolkit Map Control which is different from Bing Maps WPF Control, you can follow these steps to use Windows Community Toolkit Map Control for Windows Forms.
Note: Windows 10 (introduced v10.0.17709.0) is a prerequisite.
Create a Windows Forms Application (.NET Framework >=4.6.2 - I tried myself with 4.7.2)
Install Microsoft.Toolkit.Forms.UI.Controls NuGet package.
Add an app.manifest file: Right-click on project → Add New Item → Choose Application Manifest File (Windows Only) which is located under General node.
Open the app.manifest file and uncomment the supportedOS under <!-- Windows 10 -->:
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
Handle the Load event of your form and add the following code:
private void Form1_Load(object sender, EventArgs e)
{
var map = new MapControl();
map.Dock = DockStyle.Fill;
map.MapServiceToken = "YOUR KEY";
map.LoadingStatusChanged += async (obj, args) =>
{
if (map.LoadingStatus == MapLoadingStatus.Loaded)
{
var cityPosition = new BasicGeoposition() {
Latitude = 47.604, Longitude = -122.329 };
var cityCenter = new Geopoint(cityPosition);
await map.TrySetViewAsync(cityCenter, 12);
}
};
this.Controls.Add(map);
}
Also make sure you include required usings:
using Microsoft.Toolkit.Forms.UI.Controls;
using Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT;
Note 1: I was unable to add the control in designer because of an exception on design-time when I tried to drop the control on form, so I decided to use add it at run-time.
Note 2: You need to Get a Key to use map; however for test purpose you may ignore getting the key.
Run your application and see the result:
More information
MapControl for Windows Forms and WPF
Source code: Microsoft.Toolkit.Forms.UI.Controls.MapControl
WinForms control is a wrapper around WPF Windows.UI.Xaml.Controls.Maps.MapControl
Display maps with 2D, 3D, and Streetside views

Windows Phone 8.1 live tile background task

I have a Windows Phone 8 app that I recently upgraded to 8.1 Silverlight. I'd like to use the new tile templates. Right now I have a ScheduledTaskAgent that uses ShellTile.
In order to use the new live tiles I changed the notification service to WNS in my WMAppManifest.xml. I removed the code to register the old background task and added this code instead:
var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();
if (backgroundAccessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
backgroundAccessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
{
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == "LiveTileBackgroundTask")
{
task.Value.Unregister(true);
}
}
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = "LiveTileBackgroundTask";
taskBuilder.TaskEntryPoint = "BackgroundTasks.LiveTileBackgroundTask";
taskBuilder.SetTrigger(new TimeTrigger(15, false));
var registration = taskBuilder.Register();
}
I created a Windows Phone 8.1 Windows Runtime Component called BackgroundTasks that contains a BackgroundTask called LiveTileBackgroundTask:
public sealed class LiveTileBackgroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
const string xml = "<tile>"
+ "<visual>"
+ "<binding template='TileWideText01'>"
+ "<text id='1'>Text Field 1 (larger text)</text>"
+ "<text id='2'>Text Field 2</text>"
+ "<text id='3'>Text Field 3</text>"
+ "<text id='4'>Text Field 4</text>"
+ "<text id='5'>Text Field 5</text>"
+ "</binding> "
+ "</visual>"
+"</tile>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
TileNotification tileNotification = new TileNotification(doc);
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
deferral.Complete();
}
}
I added a reference to this assembly in my Windows Phone project.
I also added a Background task declaration in my Package.appxmanifest that has BackgroundTasks.LiveTileBackgroundTask as an Entry point. I selected Timer and System event as supported task types.
When I run the app though, nothing happens. No live tile appears. I ran through the background task and everything goes well without any exceptions.
You say "No live tile appears". The code you've posted does not create a live tile - it just updates one. You have to manually pin it - the primary tile cannot be pinned through code.
If that's not the problem, maybe you're not looking at the wide tile? This template is for a wide tile, so the square tile won't be updated by this. I'd suggest using the NotificationsExtensions library. It was originally for Windows Store apps, but I think it would work for WP as well. (I've used it, but just for a test, not for real, so there may be issues.) It allows you to easily specify the template and params for both wide and square tiles.
And finally, to have a wide tile, you have to manually edit the Package.appxmanifest file. You must add the Wide310x150Logo attribute to the DefaultTile element.
That's all I can think of. Hope it helps.
Continuous background execution is not supported for Silverlight 8.1
apps
Windows Phone 8 apps can continue to run in the background after the
user navigates away from the app under certain conditions. This
feature is not available for Silverlight 8.1 apps. If you need this
feature, you should continue to use a Windows Phone 8 app. For more
information, see Running location-tracking apps in the background for
Windows Phone 8.
Platform compatibility and breaking changes for Windows Phone Silverlight 8.1 apps
Windows Phone 8.1 Windows Runtime Component can only be used with Windows Phone 8.1 Runtime(Store) app

Open PDF in WPF Application

I have followed this link - Display a PDF in WPF Application to open PDF in a WPF application:
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AxAcroPDFLib.AxAcroPDF)); ` // axAcroPdf1 = new AxAcroPDFLib.AxAcroPDF();
//this.axAcroPdf1.Dock = System.Windows.Forms.DockStyle.Fill;
//this.axAcroPdf1.Enabled = true;
//this.axAcroPdf1.Name = "Demo";
//this.axAcroPdf1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAcroPdf1.OcxState")));
//axAcroPdf1.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "\\FileStorage\\Demo.pdf");
// axAcroPdf1.Visible = true;
Got an exception like this:
Could not find any resources appropriate for the specified culture or the neutral >culture. Make sure "AxAcroPDFLib.AxAcroPDF.resources" was correctly embedded or linked >into assembly "AxInterop.AcroPDFLib" at compile time, or that all the satellite >assemblies required are loadable and fully signed.

WPF WebBrowser - How to Zoom Content?

Trying to test basic browser concepts in a WPF (C#/XAML, .NET 4.0) WebBrowser application. So far, the only problem is programatically zooming. Has anyone had any experience with this?
MSDN lists nothing: http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx
Additionally, I have tried various things such as RenderTransform options to no avail. Either this is not possible or not documented. I'm hoping for the latter. Note that a WinForm solution isn't acceptable.
Thanks in advance for any help,
Beems
Maybe you can execute a javascript like this.
document.body.style.zoom = 1.5;
In WPF we can manipulate the document. I Created a Extension Method for you, so you can set the Zoom:
// www.tonysistemas.com.br
public static partial class MyExtensions
{
public static void SetZoom(this System.Windows.Controls.WebBrowser WebBrowser1, double Zoom)
{
// For this code to work: add the Microsoft.mshtml .NET reference
mshtml.IHTMLDocument2 doc = WebBrowser1.Document as mshtml.IHTMLDocument2;
doc.parentWindow.execScript("document.body.style.zoom=" + Zoom.ToString().Replace(",", ".") + ";");
}
}
Usage:
WebBrowser1.SetZoom(0.5);
I used bits and pieces from this answer https://stackoverflow.com/a/7326179/17822 to assist with the zoom issue. The key here is the ExecWB method. The zoom on the Windows Desktop is not 1-1 to the zoom on the WebBrowser Control. You will have to play with it. The pseudo-code for the equation looks like this:
zoomLevel = (winDesktopZoom - 100) + _winDesktopZoom + 10
Note that you will need a reference to SHDocVw.dll which can be found in the C:\Windows\SysWOW64 for x64 machines and in C:\Windows\System32 for x86 machines.
This is not pretty, but it is the only thing that I have found, short of upgrading to http://awesomium.com that actually matches IE default zoom settings (which default to the Windows Desktop zoom) to WebBrowser Control. Also note that the Windows Desktop Zoom only exists for Vista, Win 7 and probably 2k8 as well in the Control Panel --> Display, but I didn't check Vista or 2k8. It is not there for XP (any service pack).
To get the Windows Desktop Zoom (this does work on XP for some reason) I did:
var presentSource = PresentationSource.FromVisual(this);
if (presentSource != null && presentSource.CompositionTarget != null
&& presentSource.CompositionTarget.TransformToDevice != null)
{
_zoomPercentage = Convert.ToInt32(100 * presentSource.CompositionTarget.TransformToDevice.M11);
}
This logic is placed in the OnSourceInitialized override for that XAML Window.
You can see this:
http://chriscavanagh.wordpress.com/2010/10/04/a-real-net-4-0-webbrowser/

Display a PDF in WPF Application [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Any ideas how to display a PDF file in a WPF Windows Application?
I am using the following code to run the browser but the Browser.Navigate method does not do anything!
WebBrowser browser = new WebBrowser();
browser.Navigate("http://www.google.com");
this.AddChild(browser); // this is the System.Windows.Window
You can get the Acrobat Reader control working in a WPF app by using the WindowsFormHost control. I have a blog post about it here:
http://hugeonion.com/2009/04/06/displaying-a-pdf-file-within-a-wpf-application/
I also have a 5 minute screencast of how I made it here:
http://www.screencast.com/t/JXRhGvzvB
You could simply host a Web Browser control on the form and use it to open the PDF.
There's a new native WPF "WebBrowser" control in .NET 3.51, or you could host the Windows.Forms browser in your WPF app.
Oops. this is for a winforms app. Not for WPF. I will post this anyway.
try this
private AxAcroPDFLib.AxAcroPDF axAcroPDF1;
this.axAcroPDF1 = new AxAcroPDFLib.AxAcroPDF();
this.axAcroPDF1.Dock = System.Windows.Forms.DockStyle.Fill;
this.axAcroPDF1.Enabled = true;
this.axAcroPDF1.Name = "axAcroPDF1";
this.axAcroPDF1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAcroPDF1.OcxState")));
axAcroPDF1.LoadFile(DownloadedFullFileName);
axAcroPDF1.Visible = true;
Try MoonPdfPanel - A WPF-based PDF viewer control
http://www.codeproject.com/Articles/579878/MoonPdfPanel-A-WPF-based-PDF-viewer-control
GitHub: https://github.com/reliak/moonpdf
Just use a frame and a webbrowser like so
Frame frame = new Frame();
WebBrowserbrowser = new WebBrowser();
browser.Navigate(new Uri(filename));
frame.Content = browser;
Then when you don't need it anymore do this to clean it up:
WebBrowser browser = frame.Content as WebBrowser;
browser.Dispose();
frame.Content = null;
If you don't clean it up then you might have memory leak problems depending on the version of .NET your using. I saw bad memory leaks in .NET 3.5 if I didn't clean up.
The following code expects Adobe Reader to be installed and the Pdf extension to be connected to this.
It simply runs it:
String fileName = "FileName.pdf";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = fileName;
process.Start();
process.WaitForExit();
Disclosure: Here is a commercial one and I work for this company.
I realize that an answer has already been accepted but the following does not require Adobe Reader/Acrobat and it is a WPF solution - as opposed to Winforms. I also realize this is an old question but it has just been updated so I guess it is still actual.
PDFRasterizer.NET 3.0 allows you to render to a WPF FixedDocument. It preserves all vector graphics (PDF graphics are converted to more or less equivalent WPF elements. This is probably closest to what you need.
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
{
pdfDoc = new Document(file);
ConvertToWpfOptions convertOptions = new ConvertToWpfOptions();
RenderSettings renderSettings = new RenderSettings();
...
FixedDocument wpfDoc = pdfDoc.ConvertToWpf(renderSettings, convertOptions, 0, 9, summary);
}
You can pass the wpfDoc to e.g. the WPF DocumentViewer to quickly implement a viewer.
You can also use FoxitReader. It's free and comes with an ActiveX control that registers in the web browsers (IE and others) after you install the FoxitReader application.
So after you install FoxitReader on the system put a WebBrowser Control and set its Source property to point to the file path of your PDF file.
Check this out: http://itextsharp.sourceforge.net/
You may have to use a WindowsFormsHost, but since it is open source, you might be able to make it a little more elegant in WPF.

Resources