WPF MediaElement with source URL never HasTimeSpan?












0















I try to play a video from a URL source. When MediaOpened is fired, the test in



private void OnMediaOpened(object sender, EventArgs e)
{
if (mediaView.NaturalDuration.HasTimeSpan)
{
// ...
}
// ...
}


always returns false and positioning within the media timespan is not possible.



Remark: If I use a file as source then HasTimeSpan is true and MediaElement.NaturalDuration.TimeSpan can be retrieved.



Is this always the case for URL based sources ?



Is there another way to get the duration of a media for URL based sources ?



I'm using .net 4.6.1.










share|improve this question



























    0















    I try to play a video from a URL source. When MediaOpened is fired, the test in



    private void OnMediaOpened(object sender, EventArgs e)
    {
    if (mediaView.NaturalDuration.HasTimeSpan)
    {
    // ...
    }
    // ...
    }


    always returns false and positioning within the media timespan is not possible.



    Remark: If I use a file as source then HasTimeSpan is true and MediaElement.NaturalDuration.TimeSpan can be retrieved.



    Is this always the case for URL based sources ?



    Is there another way to get the duration of a media for URL based sources ?



    I'm using .net 4.6.1.










    share|improve this question

























      0












      0








      0








      I try to play a video from a URL source. When MediaOpened is fired, the test in



      private void OnMediaOpened(object sender, EventArgs e)
      {
      if (mediaView.NaturalDuration.HasTimeSpan)
      {
      // ...
      }
      // ...
      }


      always returns false and positioning within the media timespan is not possible.



      Remark: If I use a file as source then HasTimeSpan is true and MediaElement.NaturalDuration.TimeSpan can be retrieved.



      Is this always the case for URL based sources ?



      Is there another way to get the duration of a media for URL based sources ?



      I'm using .net 4.6.1.










      share|improve this question














      I try to play a video from a URL source. When MediaOpened is fired, the test in



      private void OnMediaOpened(object sender, EventArgs e)
      {
      if (mediaView.NaturalDuration.HasTimeSpan)
      {
      // ...
      }
      // ...
      }


      always returns false and positioning within the media timespan is not possible.



      Remark: If I use a file as source then HasTimeSpan is true and MediaElement.NaturalDuration.TimeSpan can be retrieved.



      Is this always the case for URL based sources ?



      Is there another way to get the duration of a media for URL based sources ?



      I'm using .net 4.6.1.







      wpf url mediaelement






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 14:04









      user7399085user7399085

      288




      288
























          2 Answers
          2






          active

          oldest

          votes


















          0














          The problem seems to be in the video format you use. I tested this code and it works fine.



          XAML:



           <MediaElement
          x:Name="mediaView"
          MediaOpened="OnMediaOpened"
          Source="http://mirrors.standaloneinstaller.com/video-sample/Panasonic_HDC_TM_700_P_50i.mp4" />


          Code:



           private void OnMediaOpened(object sender, RoutedEventArgs e)
          {
          if (mediaView.NaturalDuration.HasTimeSpan)
          {
          MessageBox.Show("It has TimeSpan and its duration is : " + Convert.ToString(mediaView.NaturalDuration) );
          }
          }





          share|improve this answer
























          • Yes it works with the URL you used. The URL I use for testing is "localhost:8080/SoccerApp/SpielVideoServlet?id=1832" This is a Tomcat 9 Webserver on my computer providing a self developed Java servlet. I'm testing the Http connection prior to playing the video, the 'HttpWebResponse.ContentType' is "video/mp4". Remark: Recently I have also developed a JavaFX desktop application using its MediaView. In this environment accessing the URL above delivers a duration.

            – user7399085
            Nov 16 '18 at 11:44





















          -1














          Meanwhile I can not reproduce the issue described in my question. The video streamed from my Tomcat via a servlet (see my comment to HYA's answer) now has a time span. I wonder if this is due to a "minor" update in the .Net framework.






          share|improve this answer
























          • Hm, I don't quite understand why my answer to my question was downvoted. At the time of creation of the question the issue was reproducible and I enhanced my application to cope with the situation. Some weeks later I discovered the issue has somehow gone.

            – user7399085
            Jan 8 at 11:53











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321219%2fwpf-mediaelement-with-source-url-never-hastimespan%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          The problem seems to be in the video format you use. I tested this code and it works fine.



          XAML:



           <MediaElement
          x:Name="mediaView"
          MediaOpened="OnMediaOpened"
          Source="http://mirrors.standaloneinstaller.com/video-sample/Panasonic_HDC_TM_700_P_50i.mp4" />


          Code:



           private void OnMediaOpened(object sender, RoutedEventArgs e)
          {
          if (mediaView.NaturalDuration.HasTimeSpan)
          {
          MessageBox.Show("It has TimeSpan and its duration is : " + Convert.ToString(mediaView.NaturalDuration) );
          }
          }





          share|improve this answer
























          • Yes it works with the URL you used. The URL I use for testing is "localhost:8080/SoccerApp/SpielVideoServlet?id=1832" This is a Tomcat 9 Webserver on my computer providing a self developed Java servlet. I'm testing the Http connection prior to playing the video, the 'HttpWebResponse.ContentType' is "video/mp4". Remark: Recently I have also developed a JavaFX desktop application using its MediaView. In this environment accessing the URL above delivers a duration.

            – user7399085
            Nov 16 '18 at 11:44


















          0














          The problem seems to be in the video format you use. I tested this code and it works fine.



          XAML:



           <MediaElement
          x:Name="mediaView"
          MediaOpened="OnMediaOpened"
          Source="http://mirrors.standaloneinstaller.com/video-sample/Panasonic_HDC_TM_700_P_50i.mp4" />


          Code:



           private void OnMediaOpened(object sender, RoutedEventArgs e)
          {
          if (mediaView.NaturalDuration.HasTimeSpan)
          {
          MessageBox.Show("It has TimeSpan and its duration is : " + Convert.ToString(mediaView.NaturalDuration) );
          }
          }





          share|improve this answer
























          • Yes it works with the URL you used. The URL I use for testing is "localhost:8080/SoccerApp/SpielVideoServlet?id=1832" This is a Tomcat 9 Webserver on my computer providing a self developed Java servlet. I'm testing the Http connection prior to playing the video, the 'HttpWebResponse.ContentType' is "video/mp4". Remark: Recently I have also developed a JavaFX desktop application using its MediaView. In this environment accessing the URL above delivers a duration.

            – user7399085
            Nov 16 '18 at 11:44
















          0












          0








          0







          The problem seems to be in the video format you use. I tested this code and it works fine.



          XAML:



           <MediaElement
          x:Name="mediaView"
          MediaOpened="OnMediaOpened"
          Source="http://mirrors.standaloneinstaller.com/video-sample/Panasonic_HDC_TM_700_P_50i.mp4" />


          Code:



           private void OnMediaOpened(object sender, RoutedEventArgs e)
          {
          if (mediaView.NaturalDuration.HasTimeSpan)
          {
          MessageBox.Show("It has TimeSpan and its duration is : " + Convert.ToString(mediaView.NaturalDuration) );
          }
          }





          share|improve this answer













          The problem seems to be in the video format you use. I tested this code and it works fine.



          XAML:



           <MediaElement
          x:Name="mediaView"
          MediaOpened="OnMediaOpened"
          Source="http://mirrors.standaloneinstaller.com/video-sample/Panasonic_HDC_TM_700_P_50i.mp4" />


          Code:



           private void OnMediaOpened(object sender, RoutedEventArgs e)
          {
          if (mediaView.NaturalDuration.HasTimeSpan)
          {
          MessageBox.Show("It has TimeSpan and its duration is : " + Convert.ToString(mediaView.NaturalDuration) );
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 23:46









          HYAHYA

          413




          413













          • Yes it works with the URL you used. The URL I use for testing is "localhost:8080/SoccerApp/SpielVideoServlet?id=1832" This is a Tomcat 9 Webserver on my computer providing a self developed Java servlet. I'm testing the Http connection prior to playing the video, the 'HttpWebResponse.ContentType' is "video/mp4". Remark: Recently I have also developed a JavaFX desktop application using its MediaView. In this environment accessing the URL above delivers a duration.

            – user7399085
            Nov 16 '18 at 11:44





















          • Yes it works with the URL you used. The URL I use for testing is "localhost:8080/SoccerApp/SpielVideoServlet?id=1832" This is a Tomcat 9 Webserver on my computer providing a self developed Java servlet. I'm testing the Http connection prior to playing the video, the 'HttpWebResponse.ContentType' is "video/mp4". Remark: Recently I have also developed a JavaFX desktop application using its MediaView. In this environment accessing the URL above delivers a duration.

            – user7399085
            Nov 16 '18 at 11:44



















          Yes it works with the URL you used. The URL I use for testing is "localhost:8080/SoccerApp/SpielVideoServlet?id=1832" This is a Tomcat 9 Webserver on my computer providing a self developed Java servlet. I'm testing the Http connection prior to playing the video, the 'HttpWebResponse.ContentType' is "video/mp4". Remark: Recently I have also developed a JavaFX desktop application using its MediaView. In this environment accessing the URL above delivers a duration.

          – user7399085
          Nov 16 '18 at 11:44







          Yes it works with the URL you used. The URL I use for testing is "localhost:8080/SoccerApp/SpielVideoServlet?id=1832" This is a Tomcat 9 Webserver on my computer providing a self developed Java servlet. I'm testing the Http connection prior to playing the video, the 'HttpWebResponse.ContentType' is "video/mp4". Remark: Recently I have also developed a JavaFX desktop application using its MediaView. In this environment accessing the URL above delivers a duration.

          – user7399085
          Nov 16 '18 at 11:44















          -1














          Meanwhile I can not reproduce the issue described in my question. The video streamed from my Tomcat via a servlet (see my comment to HYA's answer) now has a time span. I wonder if this is due to a "minor" update in the .Net framework.






          share|improve this answer
























          • Hm, I don't quite understand why my answer to my question was downvoted. At the time of creation of the question the issue was reproducible and I enhanced my application to cope with the situation. Some weeks later I discovered the issue has somehow gone.

            – user7399085
            Jan 8 at 11:53
















          -1














          Meanwhile I can not reproduce the issue described in my question. The video streamed from my Tomcat via a servlet (see my comment to HYA's answer) now has a time span. I wonder if this is due to a "minor" update in the .Net framework.






          share|improve this answer
























          • Hm, I don't quite understand why my answer to my question was downvoted. At the time of creation of the question the issue was reproducible and I enhanced my application to cope with the situation. Some weeks later I discovered the issue has somehow gone.

            – user7399085
            Jan 8 at 11:53














          -1












          -1








          -1







          Meanwhile I can not reproduce the issue described in my question. The video streamed from my Tomcat via a servlet (see my comment to HYA's answer) now has a time span. I wonder if this is due to a "minor" update in the .Net framework.






          share|improve this answer













          Meanwhile I can not reproduce the issue described in my question. The video streamed from my Tomcat via a servlet (see my comment to HYA's answer) now has a time span. I wonder if this is due to a "minor" update in the .Net framework.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 20 '18 at 11:50









          user7399085user7399085

          288




          288













          • Hm, I don't quite understand why my answer to my question was downvoted. At the time of creation of the question the issue was reproducible and I enhanced my application to cope with the situation. Some weeks later I discovered the issue has somehow gone.

            – user7399085
            Jan 8 at 11:53



















          • Hm, I don't quite understand why my answer to my question was downvoted. At the time of creation of the question the issue was reproducible and I enhanced my application to cope with the situation. Some weeks later I discovered the issue has somehow gone.

            – user7399085
            Jan 8 at 11:53

















          Hm, I don't quite understand why my answer to my question was downvoted. At the time of creation of the question the issue was reproducible and I enhanced my application to cope with the situation. Some weeks later I discovered the issue has somehow gone.

          – user7399085
          Jan 8 at 11:53





          Hm, I don't quite understand why my answer to my question was downvoted. At the time of creation of the question the issue was reproducible and I enhanced my application to cope with the situation. Some weeks later I discovered the issue has somehow gone.

          – user7399085
          Jan 8 at 11:53


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321219%2fwpf-mediaelement-with-source-url-never-hastimespan%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine