Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › [C#] Youtube embedding link problem
New Posts  All Forums:Forum Nav:

[C#] Youtube embedding link problem

post #1 of 4
Thread Starter 
Hello I asked for help before on my program on adding http:// or not to a link that I would put in my textbox(if the link already contained http:// it would not add it, but, if it did not have http:// in the link it would add it ). I got it working just great with help of ocn members, I decided on embedding some youtube videos to my program. The videos may change once in a while, and I am trying to get it working when I add a youtube link to my textbox and have it work in the embed video.

(this code is really messy I apologize)

Basically when I add a youtube link I want it to check for http and if there is one it will play the youtube video in embed format (it seems I have to have http for links to work in C# webBrowser feature unless you can tell me if there is a loophole where I don't need http at all.)
Code:
        public void button1_Click(object sender, EventArgs e)
        {
            string schemeHttp = string.Format("{0}://", Uri.UriSchemeHttp);
            string userUrl = textBox1.Text;
      
            StreamWriter sw = new StreamWriter("utube.html");
            string PlayString = textBox1.Text.Trim().Replace("watch?v=", "v/");
            string Finalplaycode = "<embed src=" + PlayString + "?autoplay=1" + "&hl=en&fs=1& type=application/x-shockwave-flash   allowscriptaccess=always allowfullscreen=true width=425 height=344></embed>";
            sw.Write(Finalplaycode);
            sw.Close();
            string PathToNavigate = Directory.GetParent(Application.ExecutablePath) + @"\utube.html";

            if (!userUrl.StartsWith(schemeHttp, StringComparison.OrdinalIgnoreCase))
            {
                userUrl = string.Format("{0}{1}", schemeHttp, userUrl);
            }

            webBrowser1.Navigate(PathToNavigate);
            //webBrowser1.Navigate(new Uri(userUrl));
            webBrowser1.ScriptErrorsSuppressed = true;

           

  

        }
    
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 ECS 8800GTS 512MB G.Skill 2x 1gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 7200rpm 250GB + 1TB 7200rpm HDD Lite On DVD burner Windows 7 32 bit 21.5 inch Samsung monitor full HD 1080p :D 
KeyboardPowerCaseMouse
microsoft wireless Corsair 650 watts Cooler Master 690 Logitech mx518 
Mouse Pad
fryz mousepad 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 ECS 8800GTS 512MB G.Skill 2x 1gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 7200rpm 250GB + 1TB 7200rpm HDD Lite On DVD burner Windows 7 32 bit 21.5 inch Samsung monitor full HD 1080p :D 
KeyboardPowerCaseMouse
microsoft wireless Corsair 650 watts Cooler Master 690 Logitech mx518 
Mouse Pad
fryz mousepad 
  hide details  
Reply
post #2 of 4
Use the Uri class in .net. Example:
Code:
var url = new Uri(userUrl);
if(url.IsAbsoluteUri){
   //Do something that requires http or https, ftp, etc in the beginning of the URL
   if(url.Scheme == "http")
   {
      //Do something only for http (requires that the url is absolute for Scheme to work)
   }
}



See this http://msdn.microsoft.com/en-us/library/system.uri(v=vs.100).aspx for more detail
Blacky
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 ASUS Maximus Formual SE ATi 4870 512mb 4GB DDR2 
Hard DriveOptical DriveOSMonitor
2x 80GB Intel SSD Raid 0, 3x 1TB Raid 5 Blueray+hd-dvd Windows 7 x64 24" Acer 1900x1200 
KeyboardPowerCaseMouse
Deck Green fullsize SilverStone SST-ST60F 600w LanLi PC-61B Logitech MX revolution 
  hide details  
Reply
Blacky
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 ASUS Maximus Formual SE ATi 4870 512mb 4GB DDR2 
Hard DriveOptical DriveOSMonitor
2x 80GB Intel SSD Raid 0, 3x 1TB Raid 5 Blueray+hd-dvd Windows 7 x64 24" Acer 1900x1200 
KeyboardPowerCaseMouse
Deck Green fullsize SilverStone SST-ST60F 600w LanLi PC-61B Logitech MX revolution 
  hide details  
Reply
post #3 of 4
Looks like that code already does what it is supposed to do...
And no, you must include a properly formed URL with a protocol (i.e. http) for it to work ... smile.gif
My System
(30 items)
 
"Zeus"
(13 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i5 2500K (4.5ghz @ 1.320v) Gigabyte Z68X-UD3R-B3 MSI R7970 Lightning Corsair 16GB (4x4GB) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Crucial M4 128GB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 7 Ultimate 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2212HM Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Microsoft IntelliMouse Optical  XTRAC Ripper XXL 
AudioAudioAudioAudio
Westone W3 IEMs RE-272 IEMs Shure SE-215 IEMs Schiit Bifrost DAC 
AudioAudio
Schiit Asgard 2 amp HiVi Swan M50W 2.1 
CPUMotherboardGraphicsRAM
Intel Core i7 950 GA-X58-UD3R Radeon HD 5450  24GB Corsair @ 1333mhz 
Hard DriveOSPowerCase
4x WD Cavair Red 1TB in RAID 0 Windows Server 2008 R2 x64 Corsair HX-520 LianLi LanCool 
  hide details  
Reply
My System
(30 items)
 
"Zeus"
(13 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i5 2500K (4.5ghz @ 1.320v) Gigabyte Z68X-UD3R-B3 MSI R7970 Lightning Corsair 16GB (4x4GB) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Crucial M4 128GB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 7 Ultimate 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2212HM Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Microsoft IntelliMouse Optical  XTRAC Ripper XXL 
AudioAudioAudioAudio
Westone W3 IEMs RE-272 IEMs Shure SE-215 IEMs Schiit Bifrost DAC 
AudioAudio
Schiit Asgard 2 amp HiVi Swan M50W 2.1 
CPUMotherboardGraphicsRAM
Intel Core i7 950 GA-X58-UD3R Radeon HD 5450  24GB Corsair @ 1333mhz 
Hard DriveOSPowerCase
4x WD Cavair Red 1TB in RAID 0 Windows Server 2008 R2 x64 Corsair HX-520 LianLi LanCool 
  hide details  
Reply
post #4 of 4
Thread Starter 
Quote:
Originally Posted by tompsonn View Post

Looks like that code already does what it is supposed to do...
And no, you must include a properly formed URL with a protocol (i.e. http) for it to work ... smile.gif

ya just the code is not working, sure it works when I put the link in and loads the website but I am wanting to work in embed format.
    
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 ECS 8800GTS 512MB G.Skill 2x 1gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 7200rpm 250GB + 1TB 7200rpm HDD Lite On DVD burner Windows 7 32 bit 21.5 inch Samsung monitor full HD 1080p :D 
KeyboardPowerCaseMouse
microsoft wireless Corsair 650 watts Cooler Master 690 Logitech mx518 
Mouse Pad
fryz mousepad 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
E8400 3.0ghz OC @ 3.8GHz @ 1.36v DFI BLood Iron P35 ECS 8800GTS 512MB G.Skill 2x 1gb DDR2 800 CAS @ 5-6-6-21 
Hard DriveOptical DriveOSMonitor
Seagate Barracuda 7200rpm 250GB + 1TB 7200rpm HDD Lite On DVD burner Windows 7 32 bit 21.5 inch Samsung monitor full HD 1080p :D 
KeyboardPowerCaseMouse
microsoft wireless Corsair 650 watts Cooler Master 690 Logitech mx518 
Mouse Pad
fryz mousepad 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › [C#] Youtube embedding link problem