integrate vivotek ip camera in C# windows application using VitaminCtrl - camera

i develop a application to get video from vivotek ip camera the code is given below but it shows connecting to 10.60.13.12... video is not received
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VITAMINDECODERLib;
using AxVITAMINDECODERLib;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnconnect_Click_1(object sender, EventArgs e)
{
string strPreIP = "http://";
if (txtip.TextLength != 0)
axVitaminCtrl1.Url = strPreIP + txtip.Text;
// Port
axVitaminCtrl1.HttpPort = Convert.ToInt32(txtport.Text);
// User name
if (txtusername.TextLength != 0)
axVitaminCtrl1.UserName = txtusername.Text;
// Password
if (txtpass.TextLength != 0)
axVitaminCtrl1.Password = txtpass.Text;
// View stream
axVitaminCtrl1.ViewStream = (VITAMINDECODERLib.EDualStreamOption)comboviewstream.SelectedIndex.GetHashCode();
// Protocol
axVitaminCtrl1.ConnectionProtocol = (VITAMINDECODERLib.EConnProtocol)comboprotocol.SelectedIndex.GetHashCode() + 1;
axVitaminCtrl1.Connect();
}
private void button1_Click(object sender, EventArgs e)
{
axVitaminCtrl1.Disconnect();
}
private void comboviewstream_SelectedIndexChanged(object sender, EventArgs e)
{
axVitaminCtrl1.ViewStream = (VITAMINDECODERLib.EDualStreamOption)((System.Windows.Forms.ComboBox)sender).SelectedIndex.GetHashCode();
}
private void axVitaminCtrl1_OnVideoCodec(object sender, _IVitaminCtrlEvents_OnVideoCodecEvent e)
{
e.eVideoCodec = VITAMINDECODERLib.EVideoCodecType.eViCodecMJpeg;
}
}
}

You should check debug/release platform (change it to x86)
Your pc that run this program and the camera should have same subnet

Related

Xamarin forms how to keep label text value after navigation

On my Main Page, I will set my label text (#lblStartDateTime) to current time stamp when user click on a button. It will navigate to Second Page, and once I click "done" button, it will go back to Main Page.
When I navigate back to Main Page from Second Page, my label text disappeared. Does anyone know how to keep the label text value after navigation?
Main Page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Test
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainPage: ContentPage
{
public string previouspagevalue;
public MainPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
lblEndDT.Text = previouspagevalue;
}
private void btnOffline_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new SecondPage());
string currentDT = DateTime.Now.ToString();
lblStartDT.Text = currentDT;
}
}
}
Second Page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Test
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class SecondPage: ContentPage
{
public SecondPage()
{
InitializeComponent();
}
protected void btnDone_Clicked(object sender, EventArgs e)
{
MainPage mainpage = new MainPage();
string edt = DateTime.Now.ToString();
lblEndDateTime.Text = edt;
mainpage.previouspagevalue = lblEndDateTime.Text;
Navigation.PushAsync(mainpage);
}
}
}
In you btnDone_Clicked event , you should use Navigation.PopAsync to go back to MainPage, Navigation.PushAsync(mainpage); means to go to a new MainPage not the previous Page.
protected void btnDone_Clicked(object sender, EventArgs e)
{
Navigation.PopAsync();
}
Please read document to learn about how NavigationPage works.
Update, you can pass the value you need to the SecondPage when you push to SecondPage:
Codes in MainPage:
public partial class MainPage : ContentPage
{
public string previouspagevalue;
public MainPage()
{
InitializeComponent();
previouspagevalue = "I'm previouspagevalue";
}
protected override void OnAppearing()
{
base.OnAppearing();
//if you set the lblEndDT.Text = "someValue"; in the secondPage, there is no need to update it here
lblEndDT.Text = previouspagevalue;
}
private void btnOffline_Clicked(object sender, EventArgs e)
{
//Pass the parametere you need when you go to SecondPage
Navigation.PushAsync(new SecondPage(this, lblEndDT));
string currentDT = DateTime.Now.ToString();
lblStartDT.Text = currentDT;
}
}
SecondPage:
public partial class SecondPage : ContentPage
{
Label MainPagelblEndDT;
MainPage mainPage;
public SecondPage()
{
InitializeComponent();
}
public SecondPage(MainPage mainP,Label lblEndDT)
{
InitializeComponent();
//Get the lblEndDT reference here
MainPagelblEndDT = lblEndDT;
//Get the MainPage reference here
mainPage = mainP;
}
private void Button_Clicked(object sender, EventArgs e)
{
string edt = DateTime.Now.ToString();
//Use it
MainPagelblEndDT.Text = edt;
mainPage.previouspagevalue = MainPagelblEndDT.Text;
Navigation.PopAsync();
}
}
I uploaded a sample project here and you can check it. Feel free to ask me any question if you have.
I would suggest you wrap your pages in a navigation stack, use a NavigationPage and navigate to next page then when you pop back it will maintain your state.
In your App.xaml.cs
MainPage = new NavigationPage(new YourFirstPage);
Then push a page into the navigation and when you want to go back just do a
Navigation.PopAsync();
Goodluck
Feel free to get back if you have queries

How do I resolve WebViewRenderer is obsolete

This is what i get as error "WebViewRenderer.WebViewRenderer() is Obsolete
"This constructor is obsolete as of version 2.5. Please use the WebViewRenderer(Context) instead
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Xamarin.Forms;
using ZoomWebView;
using Xamarin.Forms.Platform.Android;
using ZoomWebView.Droid;
using System.ComponentModel;
using Android.Webkit;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
using Xamarin.Forms.Internals;
using System.Threading.Tasks;
[assembly: ExportRenderer(typeof(MyWebView), typeof(MyWebViewRenderer))]
namespace ZoomWebView.Droid
{
public class MyWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
var element = Element as MyWebView;
Control.Settings.TextZoom = element.ZoomInLevel;
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if(Control != null)
{
Control.Settings.BuiltInZoomControls = true;
Control.Settings.DisplayZoomControls = true;
}
var element = Element as MyWebView;
Control.Settings.TextZoom = element.ZoomInLevel;
base.OnElementPropertyChanged(sender, e);
}
}
I expected the Code to run Because i followed a particular series on youtube But it's not. Please is there any thing i am doing wrong ?
You need to add the context:
public MyWebViewRenderer(Context context) : base(context)
{
}
In your code:
namespace ZoomWebView.Droid
{
public class MyWebViewRenderer : WebViewRenderer
{
public MyWebViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || Element == null)
{
return;
}
var element = Element as MyWebView;
Control.Settings.TextZoom = element.ZoomInLevel;
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if(Control != null)
{
Control.Settings.BuiltInZoomControls = true;
Control.Settings.DisplayZoomControls = true;
}
var element = Element as MyWebView;
Control.Settings.TextZoom = element.ZoomInLevel;
base.OnElementPropertyChanged(sender, e);
}
}
}
The reason it happened is quite simple Xamarin.Forms as of v2.4 marked Xamarin.Forms.Forms Context property as obsolete. So to get global context for renderer's it is necessary that you call the base class of that renderer meaning in your constructor you do the following:
public MyWebViewRenderer(Context context) : base(context)
{
}
XF now recommends you use James Montemagno's Current Activity Plugin. If you need the current context

Table Not found - SQLITE error

I'm developing windows phone 8 application.
I'm having some difficulty with my sqlite prepare statement. I get an error saying my table does not exist, although I've checked in multiple places for it, and it does exist.
It did work until I added some new tables to the SQLite database and now it just doesn't recognise any of the tables - so I'm confused!
I have also tried hardcoding the full path.. e.g. C:\App\datbase.db etc
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO.IsolatedStorage;
using SQLitePCL;
namespace WP7.VideoScanZXing.SampleApp
{
public partial class Page1 : PhoneApplicationPage
{
string connLOCDAT = "Data Source =\\Resources\\DB\\MCRS_Data.sdf;Persist Security Info=False";
string connLOCLUDAT = "Data Source =\\Resources\\DB\\MCRSLU_MYCUBE.sdf;Persist Security Info=False";
public Page1()
{
InitializeComponent();
//check the isolated storage to see if the user has saved a username and password.
CheckIsoStore();
}
public void CheckIsoStore() {
if (IsolatedStorageSettings.ApplicationSettings.Contains("UsrEmail"))
{
//The user has saved details
//populate the email and password box automatically
//Dont forget to check the save details box too
tbEmail.Text = IsolatedStorageSettings.ApplicationSettings["UsrEmail"].ToString();
pbPassword.Password = IsolatedStorageSettings.ApplicationSettings["UsrPassword"].ToString();
cbSaveDetails.IsChecked = true;
}
}
public void failedLogin()
{
MessageBox.Show("Error: Email or Password are incorrect. Please try again.");
tbEmail.Focus();
}
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
//validate user
string strEmail = tbEmail.Text;
string strPassword = pbPassword.Password.ToString();
//bool bolValidUser = false;
//validate username and password here!
if (bolValidUser(strEmail, strPassword) == true)
{
//user has been validated and can continue.
if (cbSaveDetails.IsChecked == true)
{
//save the users details here
IsolatedStorageSettings.ApplicationSettings["UsrEmail"] = strEmail;
IsolatedStorageSettings.ApplicationSettings["UsrPassword"] = strPassword;
IsolatedStorageSettings.ApplicationSettings.Save();
}
else {
IsolatedStorageSettings.ApplicationSettings.Remove("UsrEmail");
IsolatedStorageSettings.ApplicationSettings.Remove("UsrPassword");
IsolatedStorageSettings.ApplicationSettings.Save();
}
NavigationService.Navigate(new Uri("/MenuPage.xaml", UriKind.Relative));
}
else {
//redirect the user back to the home screen with a message
//NavigationService.Navigate(new Uri("/LoginPage.xaml?message=Login error ", UriKind.Relative));
failedLogin();
}
}
public static SQLiteConnection dbConn;
public bool bolValidUser(string Uname, string PWord)
{
dbConn = new SQLitePCL.SQLiteConnection(Windows.ApplicationModel.Package.Current.InstalledLocation.Path + #"\bizData.db", SQLiteOpen.READWRITE);
{
//StorageFile databaseFile = await .GetFileAsync("bizData.db");
//await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
}
//using (var statement = dbConn.Prepare(#"SELECT * FROM [MCRS_LU_Login] WHERE [Email] = " + Uname + " AND [Password] = " + PWord))
using (var statement = dbConn.Prepare(#"SELECT * FROM [BARCODES]"))
{
if (statement.Step() == SQLiteResult.ROW)
{
//new MessageDialog(Convert.ToString(statement.DataCount)).ShowAsync();
//if ()
string strLinkedUser;
strLinkedUser = statement[3].ToString();
IsolatedStorageSettings.ApplicationSettings["UsrADName"] = statement[0].ToString();
return true;
}
else
{
return false;
//await msgDialog.ShowAsync();
}
}
}
private void tbEmail_GotFocus(object sender, RoutedEventArgs e)
{
imgMail.Visibility = Visibility.Collapsed;
}
private void tbEmail_LostFocus(object sender, RoutedEventArgs e)
{
if(tbEmail.Text =="") {
imgMail.Visibility = Visibility.Visible;
}
}
private void pbPassword_LostFocus(object sender, RoutedEventArgs e)
{
if (pbPassword.Password == "")
{
imgPassword.Visibility = Visibility.Visible;
}
}
private void pbPassword_GotFocus(object sender, RoutedEventArgs e)
{
imgPassword.Visibility = Visibility.Collapsed;
}
}
}

UnauthorizedAccessException in Webcam app

I'm trying to make a simple webcam app:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Media.MediaProperties;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
namespace App1
{
public sealed partial class MainPage : Page
{
private Windows.Media.Capture.MediaCapture m_mediaCaptureMgr;
private Windows.Storage.StorageFile m_photoStorageFile;
private readonly String PHOTO_FILE_NAME = "photo.jpg";
public MainPage()
{
this.InitializeComponent();
}
internal async void initializeCamera()
{
m_mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
await m_mediaCaptureMgr.InitializeAsync();
statusBox.Text = "initialized";
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
internal async void takePicture(object sender, RoutedEventArgs e)
{
m_photoStorageFile = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
await m_mediaCaptureMgr.CapturePhotoToStorageFileAsync(imageProperties, m_photoStorageFile);
}
private void initializeButton(object sender, RoutedEventArgs e)
{
initializeCamera();
}
}
}
However, when I click on the initializeButton, I got an exception:
UnauthorizedAccessException (Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)))
What could be the problem here?
EDIT: I found the bug. Basically, if the webcam is already initialized, trying to initialize it again will trigger an exception. So I had to put in a flag, and some try/catch
Have you set the capabilities for Microphone and Webcam in the manifest file?
Seect the Microphone and Webcam capability in Package.Appmnifest file

Why should we actually use Dependency Properties?

This code doesn't work :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverlightPlainWCF.CustomersServiceRef;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace SilverlightPlainWCF
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.DataContext = Customers;
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
public static readonly string CustomersPropertyName = "Customers";
// public DependencyProperty CustomersProperty = DependencyProperty.Register(CustomersPropertyName,typeof(ObservableCollection<Customer>)
// ,typeof(MainPage),new PropertyMetadata(null));
private ObservableCollection<Customer> customers;
public ObservableCollection<Customer> Customers
{
//get { return GetValue(CustomersProperty) as ObservableCollection<Customer>; }
//set
//{
// SetValue(CustomersProperty, value);
//}
get
{
return customers;
}
set
{
customers = value;
}
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
CustomersServiceClient objCustomersServiceClient = new CustomersServiceClient();
objCustomersServiceClient.GetAllCustomersCompleted += (s, res) =>
{
if (res.Error == null)
{
Customers = res.Result;
}
else
{
MessageBox.Show(res.Error.Message);
}
};
objCustomersServiceClient.GetAllCustomersAsync();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
// Do not load your data at design time.
// if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
// {
// //Load your data here and assign the result to the CollectionViewSource.
// System.Windows.Data.CollectionViewSource myCollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["Resource Key for CollectionViewSource"];
// myCollectionViewSource.Source = your data
// }
// Do not load your data at design time.
// if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
// {
// //Load your data here and assign the result to the CollectionViewSource.
// System.Windows.Data.CollectionViewSource myCollectionViewSource = (System.Windows.Data.CollectionViewSource)this.Resources["Resource Key for CollectionViewSource"];
// myCollectionViewSource.Source = your data
// }
}
private void LayoutRoot_MouseLeave(object sender, MouseEventArgs e)
{
}
private void customerDataGrid_RowEditEnded(object sender, DataGridRowEditEndedEventArgs e)
{
var Customer = Customers[e.Row.GetIndex()];
Debug.WriteLine(Customer);
}
private void customerDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
}
}
Whereas if i just change the above property of Customers to this :-
public static readonly string CustomersPropertyName = "Customers";
public DependencyProperty CustomersProperty = DependencyProperty.Register(CustomersPropertyName,typeof(ObservableCollection<Customer>)
,typeof(MainPage),new PropertyMetadata(null));
private ObservableCollection<Customer> customers;
public ObservableCollection<Customer> Customers
{
get { return GetValue(CustomersProperty) as ObservableCollection<Customer>; }
set
{
SetValue(CustomersProperty, value);
}
}
it works. Why is it that only with DependencyProperty the grid gets populated? Please explain me in little detail. Also, do i have to compulsorily use ObservableCollection or even List is fine?
Short answer: Dependency properties are wrappers which know how to 'dispatch changes'.
See Dependency Properties Overview