2017-04-05 5 views
0

最初の試み:WMPLibをプロジェクトの参照として追加してプログラムでWindows Media Playerを作成しました。私はASP.Net Webページ(Visual Studio 2015)でWindows Media Playerを使用してプレイリストを再生しようとしています。 HTML5の例で使用されているビデオタグを使用することはできません。コントロールに.wmv、.mp4、.jpgの形式を表示する必要があります。コードを実行すると、エラーは表示されず、空のブラウザが表示されます。何が欠けていますか?ASP.NETのWindows Media Player C#

WMPLib.WindowsMediaPlayer Player; 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     FileNames();    
    } 

    public void FileNames() 
    { 
     String[] extentions = { "*.wmv", "*.mp4", "*.jpg" }; 
     List<string> files = new List<string>(); 
     foreach (string filter in extentions) 
     { 
      files.AddRange(System.IO.Directory.GetFiles(@"C:\Documents\", filter)); 
     } 

     foreach (string ss in files) 
     { 
      String name = System.IO.Path.GetFileName(ss); 
      Player = new WMPLib.WindowsMediaPlayer(); 

      WMPLib.IWMPPlaylist playList = Player.newPlaylist("myPlayList", ""); 
      playList.appendItem(Player.newMedia(name)); 
      Player.currentPlaylist = playList; 
      Player.controls.play(); 
     } 
    } 

私は良い方法ではありません、ハードコードされたパスを認識していが、しかし、私はちょうどこの私のローカルマシン上での表示を取得する必要があります: は、ここに私のサンプルコードです。 ありがとう!

+0

もちろん、あなたのコードはあなたのマシン上でWMPを開きますが、ブラウザからあなたのページにアクセスするにはどうすればいいですか?あなたが書いたコードは単にサーバー側で発生します。 – Filburt

+0

ありがとうございました。私はそれをどのように働かせるのですか?私は "Page.Controls.Add(Player);"の行で何かを試しました;これの正しい実装は何でしょうか? – BabyDoll

+0

ウィンドウコントロールを追加することはできません。これを動作させる方法については、[HTMLプレーヤーでwmvビデオを再生するには?](http://stackoverflow.com/q/23260092/205233)を参照してください。 – Filburt

答えて

0

さらに2週間の研究の後、私たちは、表示する必要のあるコンテンツに基づいて、さまざまな種類のコントロールを切り替えることによって解決策を導き出すことができました。 PowerPointのスライドショーを表示するには、すべてのスライドを画像に変換して、コレクションをループしました。背後

<body> 
<form id="form1" runat="server"> 

    <%-- Video DIV --%> 
    <div runat="server" id="VidDiv" class="fullscreen-bg"> 
    </div> 
    <%-- IMAGE DIV --%> 
    <div runat="server" id="container"> 
     <div runat="server" id="containers"> 
     </div> 
     <%-- this is where the code gets dynamically created --%> 
    </div> 
</form> 
</body> 
    <script src="Scripts/jquery-3.1.1.js"></script> 
    <script id="CallMyFunction" type="text/javascript"> 
      var index = 1; 
    document.getElementById("VidDiv").style.display = "none"; 

var ImageCount = 1; 
autoSlide(); 

function autoSlide() { 

    var x = document.getElementsByClassName("Images"); 
    var video_player = document.getElementsByClassName("fullscreen-bd__video"); 
    var count; 
    var video; 
    var videoSource = new Array(), vids, i; 

    for (i = 0; i < x.length; i++) { 
     x[i].style.display = "none"; 
    } 
    if (index > x.length) { 
     index = 1 
    } 

    x[index - 1].style.display = "block"; 

    count = x.length; 

    if (ImageCount <= count) { 
     index++; 
     ImageCount = 1 + ImageCount; 
     setTimeout(autoSlide, 8000); 
    } 
    else { 
     //this is where we should switch from image div to video div 
     document.getElementById("container").style.display = "none"; 
     document.getElementById("VidDiv").style.display = "block"; 

     //create a counter to check the number of video tags 
     video = document.getElementsByTagName('video'), numVideos = video.length; 

     for (i = 0; i < numVideos; i++) { 

      videoSource[i] = video.item(i).src; 
      document.getElementById("myVideo" + i).style.display = "none"; 
     } 

     var videoCount = 0; 
     if (videoCount <= numVideos -1) { 

      function videoPlay(videoNum) { 
       if (videoCount > 0) 
       { 
        document.getElementById("myVideo" + (videoCount - 1)).style.display = "none"; 
       } 
       document.getElementById("myVideo" + videoCount).style.display = "block"; 

       document.getElementById("myVideo" + videoCount).setAttribute("src", "" + videoSource[videoCount] + ""); 
       document.getElementById("myVideo" + videoCount).load(); 
       document.getElementById("myVideo" + videoCount).play(); 
       onEndedVid = document.getElementById("myVideo" + videoCount); 

       var onEndedVid; 
       onEndedVid.onended = function() { 
        //at the end of the video, close full screen 
        myHandler(); 
       }; 

       videoCount = videoCount + 1; 

      } 

      function myHandler() { 

       if (videoCount == numVideos) { 
        //this is where we should switch from image div to video div 
        document.getElementById("container").style.display = "none"; 
        document.getElementById("VidDiv").style.display = "none"; 

        location.reload(); 
       } 
       else { 
        videoPlay(videoCount); 
       } 
      } 
      myHandler(); 

     } 
     else 
     { 
      ///back to images 
      //refresh the page 
      location.reload(); 
     }   
    } 
} 

コード::コードは明らかに改善し、最適化することができ

// this will be a watcher that checks if is new content... if there is, delete the existing .wpl file and recreate the .wpl with new content links included   
    private void CreateNewPlayList(string folder) 
    { 
     try 
     { 
      System.Threading.Thread.Sleep(5000); 
      fileName = getDrive(folder) + @"\" + folder + "Playlist.wpl"; 
      FileInfo fileInfo = new FileInfo(fileName); 

      String f = @"<?wpl version=""1.0""?> 
      <smil> 
      <head><meta name=""Generator"" content=""Microsoft Windows Media 
     Player -- 10.0.0.3646""/> 
      <author/> 
      <title> a title goes here </title> 
      </head> 
      <body> 
      <seq> "; 
       String ff = @" 
     </seq> 
     </body> 
     </smil>"; 
       using (FileStream fs = fileInfo.Create()) 
      { 
       Byte[] txt = new UTF8Encoding(true).GetBytes(f); 
       fs.Write(txt, 0, txt.Length); 

       ////write paths and load only certain file types according to requirements into array 
       String[] extentions = { "*.mp4", "*.wmv", "*.JPG".ToLower(), "*.ppt", "*.png" }; 

       List<string> files = new List<string>(); 

       foreach (string filter in extentions) 
       { 
        files.AddRange(System.IO.Directory.GetFiles(getDrive(folder) + @"\", filter)); 
       } 

       int filecount = files.Count; 
       string[] video_lists = new string[files.Count]; 

       int counts = 0; 
       foreach (string file in files) 
       { 
        video_lists[counts] = file.ToString(); 
        string PathfileName = Path.GetFileName(file); 
        Byte[] author; 
        //use the ppt to be able to go into the folder and add each slide as part of the playlist 
        if (Path.GetExtension(PathfileName) == ".ppt" || Path.GetExtension(PathfileName) == ".pptx") 
        { 
         //create a loop to loop through the folder that has the same name as ppt/pptx(PathFileName) 
         string pptDrive = getDrive(folder) + @"\" + Path.GetFileNameWithoutExtension(PathfileName) + @"\"; 
         if (Directory.Exists(pptDrive)) 
         { 
          string[] pptFilesFolder = Directory.GetFiles(pptDrive); 
          int counter = 1; 
          while (counter <= pptFilesFolder.Length) 
          { 
           foreach (string pptFile in pptFilesFolder) 
           { 
            string pptFileName = Path.GetFileName(pptFile); 
            string pptFileNameNoExt = Path.GetFileNameWithoutExtension(pptFile);                   

            int i = pptFilesFolder.Length; 
            int ss = Convert.ToInt16(new String(pptFileNameNoExt.Where(Char.IsDigit).ToArray())); 
            if (ss <= i && ss == counter) 
            { 
             author = new UTF8Encoding(true).GetBytes(@"<media src=""" + pptDrive + @"\" + pptFileName + "\"/>"); 
             fs.Write(author, 0, author.Length); 
             counter++; 
            } 
           } 
          } 
         } 
         else 
         { 
          //do something... 
         } 

        } 
        else 
        { 
         author = new UTF8Encoding(true).GetBytes(@"<media src=""" + getDrive(folder) + @"\" + PathfileName + "\"/>"); 
         fs.Write(author, 0, author.Length); 
        } 
        counts = counts + 1; 
       } 

       Byte[] toptxt = new UTF8Encoding(true).GetBytes(ff); 
       fs.Write(toptxt, 0, toptxt.Length); 

      } 

     } 
     catch (IOException io) 
     { 
      //error handling.... 

      return; 
     } 
     catch (Exception ex) 
     { 
      //error handling... 
      return; 
     } 
    } 

ここでは他のケースの誰かのコードのスニペットは、同様の問題を持つ指導のビットが必要ですしかし、これは私たちのアプリケーションを動作させるために使用したベースです。すべてのアドバイスと入力をありがとう!

関連する問題