开发者

How to ensure video is played from website, not a cached version

开发者 https://www.devze.com 2023-03-20 03:08 出处:网络
I have used the below code(read a video from a website and play it on a panel) its working, but this video is stored on my computer.

I have used the below code(read a video from a website and play it on a panel) its working, but this video is stored on my computer.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;
namespace webplayer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                int width = panel1.Width;
                int height = panel1.Height;
              System.Uri u = new Uri("http://cassfordinfo.com/Testmovie.avi");                Video video;
              video = Video.FromUrl(u);

                video.Owner = panel1;
                video.Stop();
                video.Play();

                // resize the video to the size original size of the panel

                panel1.Size = new Size(width, height);
            }catch(Exception gh)
            {
                MessageBox.Show(gh.ToString());
            }
        }

    }
}

Once I run the exe it will read from the website but I have unplugged the internet connection and run it. It runs the same video without a connection. I have restarted my computer and again if I run the exe file I can view the video.

Whenever I need to run this program it sh开发者_StackOverflow中文版ould read it from my website not from temporary file. How can I achieve this?


I believe you want to take a look at media streaming. This can be done in a variety of ways - some would suggest silverlight though, as I understand it, it can be done through asp.Net using Windows Media Services.

It could also be done from other project types in different ways, but it looks like you need it for ASP.Net?


Although I have voted to close (I am also a bit grumpy today), here's my two cents anyway:

I assume you're using the Video Class from DirectX and so therefore the first question has to be whether you have any control over caching.

Judging by the API you can't - you just get to pass it a Uri and that's it.

Therefore I have a couple of questions:

  • Have you tried playing a video that has changed between the last play? Does the app correctly use the new version instead of the old cached version? If it does, then there's presumably no problem when a user's 'net connection is good.

  • Why must it always play the most recent version? Is it actually because if the 'net connection is down you want to make sure the user doesn't see a video? If that's the case try manually issuing an HTTP HEAD request to the video url using HttpWebRequest, or (because HEAD isn't always supported by web servers) the old trick of pinging well-known ping-friendly domain names or, even better, firing a web request at your own website - if the net connection is down you don't even try to play the video.

Finally, I guess you're after the file so you can try and delete it. My guess is that this is going to be almost nigh-on impossible to track at runtime - the file probably doesn't even have the .avi extension and is likely to be random.

Your best bet to find it on a single run, however, is to use Process Monitor to monitor your machine for file activity whilst your app connects to the video and plays it for a few seconds. Assuming the file is being accessed directly by the app (and not indirectly via some service or other exe that Dx shells) you should be able to filter the captured events down to just your app and you will see lots of file activity.

0

精彩评论

暂无评论...
验证码 换一张
取 消