c# - Accessing the resources in the published application -
i followed a tutorial on video player.
it nice imagining different situation.
i need embed videos in resources file , dynamically change videos depending on user input. have managed running inside visual studio 2010. using switch statements. have specify path of video in resources file. eg :
case 1 : video = new video("..//..//resources//the video name");
but when publish application using click once wizard, final application ends in exception :
system.nullreferenceexception: object reference not set instance of object. @ videoplayer.form1.button2_click(object sender, eventargs e) @ system.windows.forms.control.onclick(eventargs e) @ system.windows.forms.button.onclick(eventargs e).............
it seems video file not included in application. when saw installer folder, clear showed there file named videoplayer.exe.deploy of 59mb these files without resources light weighted...
it surely contains video file. cannot access file.
how access it?
please me out...
thanks in advance :-)
as asked users, posting entire code in c#.net :
the designer.cs file :
namespace playvideo { partial class form1 { // <summary> /// required designer variable. /// </summary> private system.componentmodel.icontainer components = null; /// <summary> /// clean resources being used. /// </summary> /// <param name="disposing">true if managed resources should disposed; otherwise, false.</param> protected override void dispose(bool disposing) { if (disposing && (components != null)) { components.dispose(); } base.dispose(disposing); } #region windows form designer generated code /// <summary> /// required method designer support - not modify /// contents of method code editor. /// </summary> private void initializecomponent() { this.viewport = new system.windows.forms.panel(); this.button1 = new system.windows.forms.button(); this.button2 = new system.windows.forms.button(); this.button3 = new system.windows.forms.button(); this.label1 = new system.windows.forms.label(); this.combobox1 = new system.windows.forms.combobox(); this.suspendlayout(); // // viewport // this.viewport.location = new system.drawing.point(12, 39); this.viewport.name = "viewport"; this.viewport.size = new system.drawing.size(391, 368); this.viewport.tabindex = 0; // // button1 // this.button1.location = new system.drawing.point(55, 418); this.button1.name = "button1"; this.button1.size = new system.drawing.size(79, 27); this.button1.tabindex = 0; this.button1.text = "play"; this.button1.usevisualstylebackcolor = true; this.button1.click += new system.eventhandler(this.button1_click); // // button2 // this.button2.location = new system.drawing.point(167, 418); this.button2.name = "button2"; this.button2.size = new system.drawing.size(79, 27); this.button2.tabindex = 1; this.button2.text = "pause"; this.button2.usevisualstylebackcolor = true; this.button2.click += new system.eventhandler(this.button2_click); // // button3 // this.button3.location = new system.drawing.point(279, 418); this.button3.name = "button3"; this.button3.size = new system.drawing.size(79, 27); this.button3.tabindex = 2; this.button3.text = "stop"; this.button3.usevisualstylebackcolor = true; this.button3.click += new system.eventhandler(this.button3_click); // // label1 // this.label1.autosize = true; this.label1.location = new system.drawing.point(12, 15); this.label1.name = "label1"; this.label1.size = new system.drawing.size(108, 13); this.label1.tabindex = 3; this.label1.text = "load video number : "; // // combobox1 // this.combobox1.formattingenabled = true; this.combobox1.items.addrange(new object[] { "video number 1", "video number 2", "video number 3"}); this.combobox1.location = new system.drawing.point(132, 12); this.combobox1.name = "combobox1"; this.combobox1.size = new system.drawing.size(121, 21); this.combobox1.tabindex = 4; this.combobox1.selectedindexchanged += new system.eventhandler(this.combobox1_selectedindexchanged); // // form1 // this.autoscaledimensions = new system.drawing.sizef(6f, 13f); this.autoscalemode = system.windows.forms.autoscalemode.font; this.clientsize = new system.drawing.size(415, 457); this.controls.add(this.combobox1); this.controls.add(this.label1); this.controls.add(this.button3); this.controls.add(this.button2); this.controls.add(this.button1); this.controls.add(this.viewport); this.name = "form1"; this.startposition = system.windows.forms.formstartposition.centerscreen; this.text = "video player"; this.resumelayout(false); this.performlayout(); } #endregion private system.windows.forms.panel viewport; private system.windows.forms.button button1; private system.windows.forms.button button2; private system.windows.forms.button button3; private system.windows.forms.label label1; private system.windows.forms.combobox combobox1; } }
and other .cs file :
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; using microsoft.directx.audiovideoplayback; namespace playvideo { public partial class form1 : form { private video video; public form1() { initializecomponent(); } private void combobox1_selectedindexchanged(object sender, eventargs e) { switch (combobox1.selectedindex) { case 0: video = new video("..//..//resources//video1.mp4"); break; case 1: video = new video("..//..//resources//video2.dat"); break; case 2: video = new video("..//..//resources//video3.dat"); break; } int width = viewport.width; int height = viewport.height; // set panel video object’s owner video.owner = viewport; // stop video video.stop(); // resize video size original size of panel viewport.size = new size(width, height); } private void button1_click(object sender, eventargs e) { if (video.state != stateflags.running) { video.play(); } } private void button2_click(object sender, eventargs e) { if (video.state == stateflags.running) { video.pause(); } } private void button3_click(object sender, eventargs e) { if (video.state != stateflags.stopped) { video.stop(); } } } }
and thought screenshot may of information :
it works fine in debugging mode..... once install using click once installer, crashes exception. how manage same using resources in deploy file?
you referencing files in vs solution, works fine, when debugging application, since paths valid project's \bin\debug folder. if you've set build-action resources "embedded resource", can access files using:
typeof(form1).assembly.getmanifestresourcestream("playvideo.resources.video1.dat");
msdn: http://msdn.microsoft.com/en-us/library/xc4235zt.aspx
update i've confirmed video class won't accept stream , res://-protocol cannot used either. suggest, don't embed videos executable, place them application directory. can change build-action of video-files none , change "copy output directory" property "copy if newer". once application built, videos put in output directory, can deploy along executable. should use initial approach, use path "the video name.dat" rather "..//..//resources/the video name.dat".
Comments
Post a Comment