Is it possible to embed a video to Windows Media Player? - visual-studio

I have a winform app in visual studio. On the main interface I have panels ( home panel, about us panel & contact us panel ). When I click the button that takes me to the home panel, I want the video to be there already( in Windows media player obviously ). And to be played automatically when the “ home panel button “ is clicked. The client shouldn’t have to go and look for the video.
Is there a way to do this?
Please help.

Add WMP control to the "Toolbox" panel in Visual Studio: https://learn.microsoft.com/en-us/windows/desktop/wmp/using-the-windows-media-player-control-with-microsoft-visual-studio
Drag WMP control from Toolbox to your Home panel in the form designer.
Add the video to the project and in it's properties, choose "Copy if newer" in "Copy to Output Directory" option.
Override Form.OnLoad or find another suitable place and add code that gives the player the URL of the video and sets other properties.
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var location = Assembly.GetExecutingAssembly().Location;
var folder = Path.GetDirectoryName(location);
var path = Path.Combine(folder, "small.avi");
axWindowsMediaPlayer1.URL = path;
axWindowsMediaPlayer1.uiMode = "none";
// autoplay if current page index is 0 (home?)
if (tabControl1.SelectedIndex == 0)
axWindowsMediaPlayer1.Ctlcontrols.play();
}
If you want the player to restart playback everytime the page gets displayed, add handler to TabControl.SelectedIndexChanged event:
this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.TabControl1_SelectedIndexChanged);
and implement it like this:
private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 0)
axWindowsMediaPlayer1.Ctlcontrols.play();
}

Related

Prompts on top of popup windows in Xamarin and MAUI

I have discovered the limitation of displaying prompts when they are invoked from a popup window. Specifically verified with CommunityToolkit.Maui Popups.
Here's the details:
In the Map page I have this handler for the map clicked event:
void mapClicked(object sender, MapClickedEventArgs e) {
var pin = new Pin {
Label = "Here's where it is",
Location = e.Location
};
map.Pins.Add(pin);
}
I wanted to allow the user to edit the pin label when clicking on the it, like so:
pin.InfoWindowClicked += async (s, args) => {
string pinName = ((Pin)s).Label;
await DisplayPromptAsync("Enter new label", "enter new label");
};
However, this didn't work as no DisplayPrompt was shown. I tried running it in the main thread, to no avail either.
UPDATE. I've figured it out, see answer below.
The problem arises when attempting to bring up the prompt from a popup window. Evidently, one can't have a DisplayPromptAsync (or DisplayAlert for that matter) on top of a popup.
On a platform-specific level in iOS the error message reads:
Attempt to present <UIAlertController> on <Microsoft_Maui_Controls_Platform_Compatibility_ShellFlyoutRenderer> (from <Microsoft_Maui_Controls_Platform_Compatibility_ShellFlyoutRenderer>) which is already presenting <CommunityToolkit_Maui_Core_Views_MauiPopup>.

windows phone 8.0 MediaElement plays sound without any call

When i click button no 1 , MediaElement will play the pronunciation of that sentence . then if i click button no 2 i will navigate to SoundRecord page . then if i click the back button to previous page (as you see in the picture ) again , MediaElement play the previous pronunciation that you have chosen without call any function ...
what is the reason and how can i fix this problem ?
also this is the code for play the sound files :
public void PlayPronunciation(string fileName, MediaElement soundPlayer)
{
var path = string.Format("Assets/Audio/{0}.mp3", fileName);
soundPlayer.Source = new Uri(path, UriKind.Relative);
soundPlayer.AutoPlay = true;
if (soundPlayer.CurrentState == MediaElementState.Stopped)
soundPlayer.Play();
}
For temporary solution in page unload event i did something like this but i think this not a nice way to fix my problem :
private void PhoneApplicationPage_Unloaded(object sender, RoutedEventArgs e)
{
SoundPlayer.AutoPlay = false;
}
Remove this line: soundPlayer.AutoPlay = true; if you use
if (soundPlayer.CurrentState == MediaElementState.Stopped)
soundPlayer.Play();`
Set AutoPlay="False" in the xaml and delete any soundPlayer.AutoPlay=true; from your code
Change this:
if (soundPlayer.CurrentState == MediaElementState.Stopped)
to this:
if (soundPlayer.CurrentState != MediaElementState.Playing)

Application poor responsiveness in wp7

I am showing one MessageBox inside manipulationStarted event(or Tap Event ) of an image and that is causing App poor responsiveness when we perform store monitoring test in V2012.
Xaml Image control -
<Image HorizontalAlignment="Left" Height="100" VerticalAlignment="Top"
Width="104" Margin="90,60,0,0" Grid.Row="1"
ManipulationStarted="Image_ManipulationStarted_1"
Source="Background.png"/ >
Event Code –
private void Image_ManipulationStarted_1(object sender,
ManipulationStartedEventArgs e)
{
var m = MessageBox.Show("The file will be saved here.", "File Save", MessageBoxButton.OKCancel);
if (m == MessageBoxResult.OK)
{
int temp = 10;
}
}
When I perform "Automated tests" in open store test kit for above sample code, it is causing poor responsiveness and that cause to certification failure when we upload app the the market place. Here are the steps -
Right click on Application Name in the solution explore in Visual Studio 2012
Open store test kit -> Automated test -> Start Windows Phone Analysis -> Select App Analysis -> Click on Start Session (App will start)
Application Will start running
Perform the Tap event on the image, MessageBox will appear and click OK.
Click on End Session (App Will Exit) in V2012.
The result of App Analysis will be shown in Summary. In that summary you can see the Red Line in front of Responsiveness means the application responsiveness is poor which causes certification failure.
My requirement is like that only. I have one image (As a Button) and on click i.e Tap i want to do some operation.
Note – Build is targeted to WP7 but application is running on WP8 emulator.
Regards
Mukesh Sharma
Putting up a modal dialog inside an event handler will lock up the calling thread until the dialog is dismissed. That may give poor responsiveness rating.
What you may want to try is to in the event handler just disable the image for manipulation and dispatching the MessageBox to a time after the event handler has returned, something like (the untested);
private void Image_ManipulationStarted_1(object sender,
ManipulationStartedEventArgs e)
{
// <disable image manipulation here>
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
var m = MessageBox.Show("The file will be saved here.",
"File Save", MessageBoxButton.OKCancel);
if (m == MessageBoxResult.OK)
{
int temp = 10;
}
// <enable image manipulation again>
}
}

PhotoChooserTask + Navigation

I taken two Images & added event (MouseButtonDown) for them.
When first image handles event to open Gallery. Second image handles events for open camera.
When user has choosed his image from the gallery, I want to navigate to next page. Its navigates. But before completing navigation process, it displays MainPage & then moves toward next page. I didnt want to display the MainPage once user chooses the image from the gallery.
Plz help.
Thanks in advance.
public partial class MainPage : PhoneApplicationPage
{
PhotoChooserTask objPhotoChooser;
CameraCaptureTask cameraCaptureTask;
// Constructor
public MainPage()
{
InitializeComponent();
objPhotoChooser = new PhotoChooserTask();
objPhotoChooser.Completed += new EventHandler<PhotoResult>(objPhotoChooser_Completed);
cameraCaptureTask = new CameraCaptureTask();
cameraCaptureTask.Completed += new EventHandler<PhotoResult>(objCameraCapture_Completed);
}
void objPhotoChooser_Completed(object sender, PhotoResult e)
{
if (e != null && e.TaskResult == TaskResult.OK)
{
//Take JPEG stream and decode into a WriteableBitmap object
App.CapturedImage = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
//Delay navigation until the first navigated event
NavigationService.Navigated += new NavigatedEventHandler(navigateCompleted);
}
}
void navigateCompleted(object sender, EventArgs e)
{
//Do the delayed navigation from the main page
this.NavigationService.Navigate(new Uri("/ImageViewer.xaml", UriKind.RelativeOrAbsolute));
NavigationService.Navigated -= new NavigatedEventHandler(navigateCompleted);
}
void objCameraCapture_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
//Take JPEG stream and decode into a WriteableBitmap object
App.CapturedImage = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
//Delay navigation until the first navigated event
NavigationService.Navigated += new NavigatedEventHandler(navigateCompleted);
}
}
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}
private void image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
objPhotoChooser.Show();
}
private void image2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
cameraCaptureTask.Show();
}
To my knowledge when you use one of the choosers, like the Photo gallery or the camera, when your application is activating it will take it back to the page you left it. I don't think there is a way to get around this itself. What you would have to do is catch the Activating event in your main page code and Navigate to the desired page from there.
Now I am not completely sure how you would pass the image from the MainPage to the target page. It does not look like there is a property in the Navigation service to store this value. But you could either set it in an application wide variable, ModelView or even store it in the Isolated Storage area.
You could work around this by navigating to an intermediate blank page and have that intermediate page launch the tasks. When the tasks are completed you can then navigate as normal to your new page and only this blank page will show in transit.
Chris is correct that some of the tasks will navigate away from your app (effectively tombstoning it) and will the re-activate your application when the user returns from the task. For the camera this is particularly difficult, as to my knowledge there is no simple way to detect when you are returning from the camera. Also the camera doesn't work when attached to the debugger or Zune software (at least this is true on my HTC Surround), which makes troubleshooting quite difficult!
In my WP7 Barcode Scanning application I ended up using flags on the PhoneApplicationService class to help track where the navigation events are coming from. Something like:
PhoneApplicationService.Current.State["ReturnFromSampleChooser"] = true;
You can then check for these flags in the PhoneApplicationPage_Loaded or OnNavigatedTo method of your main page and redirect to the desired page as needed. Just make sure to clear the flag and be careful to not cause any loops in the navigation, as that might make your app fail certification (back button must ALWAYS work correctly).
For an example of how to use the camera and set/clear flags using PhoneApplicationService check out the source code for the Silverlight ZXing Barcode Library. You can download the full source here or browse the files online.

Windows Phone 7 TopProperty Changed event

I want to do some code after Canvas.topProperty is changed in my control.
I've seen examples with DependencyPropertyDescriptor but Visual studio do not recognize this class in Windows Phone 7 project.
How can I manage this problem?
What you need to look at is the LayoutUpdated event handler for the canvas.
First of all you need to store the value of the top margin in a separate field/property.
double top = 0;
top = YourCanvas.Margin.Top;
Then, in the LayoutUpdated event handler you can check whether the margin was modified:
void LayoutRoot_LayoutUpdated(object sender, EventArgs e)
{
if (LayoutRoot.Margin.Top != top)
{
// Your action here
Debug.WriteLine("CHANGED!");
}
}

Resources