I am hoping someone can help me, i want to play another video file, however when i double click another video file it doesnt play it and just shows the last frame from the first video file. i am not sure what i am doing wrong.
below is my code
void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
string final = "file path";
playfile(final);
}
void playfile(string final)
{
var control = new VlcControl();
var currentAssembly = Assembly.GetEntryAssembly();
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
// Default installation path of VideoLAN.LibVLC.Windows
var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
control.BeginInit();
control.VlcLibDirectory = libDirectory;
control.Dock = DockStyle.Fill;
control.EndInit();
panel1.Controls.Add(control);
control.ResetMedia();
control.Play(new Uri(final).AbsoluteUri);
}
i have tried things like
control.Dispose();
control.ResetMedia();
control.Update();
control.Refresh();
i have even tried to manipulate the panel however that didnt work
Thank you
seems as if i did not clear the panel correctly if anyone is having trouble with the same issue i used this
panel1.Controls.Clear();
panel1.Update();
panel1.Refresh();
You don't need to destroy/add a new control each time. You could use the same player and just use
control.Play(newMedia);
Related
My default background image is "lobby.jpg" and when I click the "Lights" button I want it to swap with "lobby1.jpg" and vice versa. These images are stored in "obj\Debug\Images\".
Also I'd like to implement relative(?) imagesource uris so that I can access the images on any machine (without using the whole uri, just the "obj\Debug\Images\").
Edit: So the main issue seems to be that I tried changing the window background without realising that it was getting "covered" by the grid background of the page. So what I did is I set the main window background to "lobby.jpg", I made the grid background invisible and used the code from the answer to swap between the 2 backgrounds.
You can use AppDomain basepath to exe (this is are simplest way)
var basePath= AppDomain.CurrentDomain.BaseDirectory;
var imageDirPath = $"{basePath}\\Images\\";
Example:
bool clicked = false;
private void button_Click(object sender, RoutedEventArgs e)
{
var basePath = AppDomain.CurrentDomain.BaseDirectory;
var imageDirPath = $"{basePath}\\Images\\";
if (clicked)
image.Source = new BitmapImage(new Uri(imageDirPath+ "lobby.jpg"));
else
image.Source = new BitmapImage(new Uri(imageDirPath + "lobby1.jpg"));
clicked = !clicked;
}
I'm a novice programmer so don't be brutal.
I'm making a game for Windows Store, and I want to animate a run cycle. I made many GIF animations but all have BLACK background, and I need it transparent. So I've decided to make a run cycle using DispatcherTimer. Everything works fine, but the images don't change :/
void timer_Tick(object sender, object e)
{
numer++;
if (numer > 8) numer = 1;
hero.Source.Equals("Assets/Anim/" + nazwa + numer + ".png");
}
Also, When I TAP a different image, it should change the image and other images, but it doesn't... what is wrong?
bool sun = true;
private void Image_Tapped(object sender, TappedRoutedEventArgs e)
{
sun = !sun;
if (sun == false)
{
Image1.Source.Equals("moon.png");
Image2.Source.Equals("ON.png");
}
else
{
Image1.Source.Equals("sun.png");
Image2.Source.Equals("OFF.png");
}
}
The xaml works fine, as the images are shown.
I have checked this question:
ImageTools on Windows Phone 8, changing ImageSource and DataContext
but I get loads of errors. I don't seem to understand how the property changed works.
it seems to be a small mistake. You are using the wrong method.
Image.Source.Equals()
is a boolean method that simply compares the current source with the "source" you give as arguement and will return true or false based on the comparison.
But what you want is to set the source of the image.
So you need to use:
Image1.Source = new BitmapImage(new Uri("moon.png", UriKind.RelativeOrAbsolute));
This will set the source of the Image to the new image you want.
Assuming that "moon.png" is in the main folder in your solution, the two solutions both work:
BitmapImage tn = new BitmapImage();
tn.SetSource(Application.GetResourceStream(new Uri(#"moon.png", UriKind.Relative)).Stream);
Image1.Source = tn;
Or
Image1.Source = new BitmapImage(new Uri("moon.png", UriKind.Relative));
Good morning everyone!
I've been having some issues regarding photos in my Windows Phone app. I'm trying to take a photo and save it to a record, and then load it up again at a different point.
My idea is to take the photo using the code in this tutorial (http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394006(v=vs.105).aspx)
In my constructor:
cameraCaptureTask = new CameraCaptureTask();
cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);
lower down..
void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
//Code to display the photo on the page in an image control named myImage.
//System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
//bmp.SetSource(e.ChosenPhoto);
//System.Diagnostics.Debug.WriteLine(e.OriginalFileName);
//string imageLoc = e.OriginalFileName;
//Uri imageUri = new Uri(imageLoc, UriKind.RelativeOrAbsolute);
//StreamResourceInfo resourceInfo = Application.GetResourceStream(imageUri);
//Code I'm using just now which just displays the photograph
System.Windows.Media.Imaging.BitmapImage bmp2 = new System.Windows.Media.Imaging.BitmapImage();
bmp2.SetSource(e.ChosenPhoto);
myImage.Source = bmp2;
}
}
From my code, you can see that the commented out bit returns the location of the image which has just been taken, then attempts to load it up from there. However, when I try that, I get URI path exceptions and the like. What is going wrong here and what method should I use to remedy it?
I'd like to be able to add the file path to a record and then be able to load it back up elsewhere in my app.
Thanks for any help!
to make it short I checked on the "WinFormsChartSamples" provided by Microsoft. What I wanted to know is how to enable zooming and scrolling for Chartcontrols. The example which is shown there is pretty short.
using System.Windows.Forms.DataVisualization.Charting;
...
// Set automatic zooming
chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["Default"].AxisY.ScaleView.Zoomable = true;
// Set automatic scrolling
chart1.ChartAreas["Default"].CursorX.AutoScroll = true;
chart1.ChartAreas["Default"].CursorY.AutoScroll = true;
...
I tried this and nothing happened, no zooming and no scrolling. I tried two things:
In Form1.Designer.cs I added that information to the chart.
chartArea1.Name = "ChartArea1";
chartArea1.CursorX.AutoScroll = true;
chartArea1.CursorY.AutoScroll = true;
chartArea1.AxisX.ScaleView.Zoomable = true;
chartArea1.AxisY.ScaleView.Zoomable = true;
this.chart1.ChartAreas.Add(chartArea1);
this.chart1.Cursor = System.Windows.Forms.Cursors.Cross;
legend1.Name = "Legend1";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(297, 62);
this.chart1.Name = "chart1";
series1.ChartArea = "ChartArea1";
series1.Legend = "Legend1";
series1.Name = "Series1";
this.chart1.Series.Add(series1);
this.chart1.Size = new System.Drawing.Size(963, 668);
this.chart1.TabIndex = 6;
this.chart1.Text = "chart1";
I tried to add it directly into the constructor in Form1.cs.
Perhaps it is important to mention that I am using OpenFileDialog in order to add data to the series:
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream fileStream = null;
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open File..";
//First the description of the file separated by "|"
fDialog.Filter = "((ASC files)| *.asc";
fDialog.InitialDirectory = #"C:\";
//Show Messagebox if the file was loaded (Source: MSDN - FileDialog.FilterProperty)
if (fDialog.ShowDialog() == DialogResult.OK)
{
MessageBox.Show("The File was loaded successfully.");
try
{
if ((fileStream = fDialog.OpenFile()) != null)
{
using (fileStream)
{
//Insert code for reading the stream here.
Spectrum newSpectrum = new Spectrum(chart1.Series.Count, fDialog.FileName,
fDialog.SafeFileName, DataHandler.readSpectrumFromFile(fileStream));
addSpectrumToView(newSpectrum);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Any advice is welcome, thanks in advance,
BC++
I think you were actually really looking for this:
chart1.ChartAreas["Default"].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas["Default"].CursorY.IsUserSelectionEnabled = true;
used in conjunction with what you already have should work well, which should look like this:
// Set automatic zooming
chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["Default"].AxisY.ScaleView.Zoomable = true;
// Set automatic scrolling
chart1.ChartAreas["Default"].CursorX.AutoScroll = true;
chart1.ChartAreas["Default"].CursorY.AutoScroll = true;
// Allow user selection for Zoom
chart1.ChartAreas["Default"].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas["Default"].CursorY.IsUserSelectionEnabled = true;
Have a look here: http://archive.msdn.microsoft.com/mschart There is an example there which does zooming/scrolling and much, much more! :)
To enable easy zooming, add a trackbar and use it to zoom:
private void trackBar1_Scroll(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.ScaleView.Size = trackBar1.Maximum - trackBar1.Value;
chart1.ChartAreas[1].AxisX.ScaleView.Size = trackBar1.Maximum - trackBar1.Value;
(etc for however many chart areas you have)
}
the "maximium - value" is to so that the higher the trackbar value, the fewer points are shown (closer zoom)
and make sure that in designer the 'chart1->ChartAreas->Axes->(whichever axes)->scaleview->zoomable' is set to true
A scroll bar will normally appear when a datapoint exceeds the scaleview size of an axis, if it has been set (scrolling doesn't really work reliably if left at 'auto'), if it hasn't, set it, if a scrollbar doesn't appear, a trackbar can yet again be used:
private void trackBar2_ValueChanged(object sender, EventArgs e)
{
chart1.ChartAreas[0].AxisX.ScaleView.Position = trackBar2.Value;
chart1.ChartAreas[1].AxisX.ScaleView.Position = trackBar2.Value;
(etc for however many chart areas you have)
}
Make sure you set the "Maximum" in the trackbars to a nice high number (eg 5000) and "Value" to what you desire it to load at.
Have yet to notice too much of a difference between "trackBar_Scroll" and "trackBar_ValueChanged", except "ValueChanged" works if the trackbar is moved by the program or user mouse click, whereas "Scoll" only works if moved by users mouse click.
Anything I missed?
My users dislikes the standard behavior of the mschart zooming and scrolling. That's why I implement a mouse based zoom/scroll that use dragging and mousewheel on axises.
The source code is here: https://bitbucket.org/controlbreak/mschartfriend
It is very simple and short, you can change it very quickly if you need.
I am developing a very simple application that parses an XML feed, does some formatting and then displays it in a TextBlock. I've added a hyperLink (called "More..) to the bottom of the page (ideally this would be added to the end of the TextBlock after the XML has been parsed) to add more content by changing the URL of the XML feed to the next page.
The issue I'm experiencing is an odd one as the program works perfectly when in the Windows Phone 7 Emulator, but when I deploy it to the device or debug on the device, it works for the first click of the "More..." button, but the ones after the first click just seem to add empty space into the application when deployed or debugged from the device.
I'm using a Samsung Focus (NoDo) and originally thought this may have had to do with the fact that I may not have had the latest developer tools. I've made sure that I am running the latest version of Visual Studio and am still running into the issue.
Here are some snippets of my code to help out.
I've declared the clickCount variable here:
public partial class MainPage : PhoneApplicationPage
//set clickCount to 2 for second page
int clickCount = 2;
Here is the snippet of code I use to parse the XML file:
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
ListBoxItem areaItem = null;
StringReader stream = new StringReader(e.Result);
XmlReader reader = XmlReader.Create(stream);
string areaName = String.Empty;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "example")
{
areaName = reader.ReadElementContentAsString();
areaItem = new ListBoxItem();
areaItem.Content = areaName;
textBlock1.Inlines.Add(areaName);
textBlock1.Inlines.Add(new LineBreak());
}
}
}
}
}
and the code for when the hyperLink button is clicked:
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
int stringNum = clickCount;
//URL is being incremented each time hyperlink is clicked
string baseURL = "http://startofURL" + stringNum + ".xml";
Uri url = new Uri(baseURL, UriKind.Absolute);
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(url);
//increment page number
clickCount = clickCount + 1;
}
It feels like there's a little more debugging to do here.
Can you test where exactly this is going wrong?
is it the click that is not working on subsequent attempts?
is it the HTTP load which is failing?
is it the adding of inline text which is failing?
Looking at it, I suspect it's the last thing. Can you check that your TextBlock is expecting Multiline text? Also, given what you've written (where you don't really seem to be making use of the Inline's from the code snippet I've seen), it might be easier to append add the new content to a ListBox or a StackPanel rather than to the inside of the TextBlock - ListBox's especially have some benefit in terms of Virtualizing the display of their content.