zoukankan      html  css  js  c++  java
  • UWP 播放直播流 3MU8

    UWP 播放直播流 3MU8
    参考:http://www.c-sharpcorner.com/UploadFile/2b876a/http-live-streaming-in-windows-10-uwp/
    Create new Windows 10 project and go to MainPage.xaml page design view to design.
    Add Media control to play the streamed videos and use the following code to design media control:
    <Grid>  
       <MediaElement x:Name="liveMedia" />  
    </Grid>  
    Next add two app bar controls to Play and Pause the streaming.
    <Page.BottomAppBar>  
       <AppBar IsOpen="True">  
          <StackPanel Orientation="Horizontal">  
             <AppBarButton Name="playBtn" Click="playBtn_Click" Icon="Play" Label="Play"></AppBarButton>  
             <AppBarButton Name="pausBtn" Click="pausBtn_Click" Icon="Pause" Label="Pause"></AppBarButton>  
          </StackPanel>  
       </AppBar>  
    </Page.BottomAppBar>  
    Next go to code behind page and write the following code to stream the video:
    var streamUri = new Uri(""); //replace your URL  
    var streamResponse = await AdaptiveMediaSource.CreateFromUriAsync(streamUri);  
    if (streamResponse.Status == AdaptiveMediaSourceCreationStatus.Success)  
    liveMedia.SetMediaStreamSource(streamResponse.MediaSource);  
    else  
    {  
       //not found  
    }  
    Before set the media source check the status property to verify that everything went correct otherwise skip it.
    By default it will start playing the stream. If you want to pause write the following code:
    private void pausBtn_Click(object sender, RoutedEventArgs e)  
    {  
       liveMedia.Pause();  
    }  
    If you want to play again write the following code:
    private void playBtn_Click(object sender, RoutedEventArgs e)  
    {  
       liveMedia.Play();  
    }  
    You can play around the media control like the following function: pause, play, mute, unmute and volume increase etc.
    Now run the app and check the output like the following video. Here I am going to stream the live news channel. 
  • 相关阅读:
    SecureCRT安装
    wmv12下安装centos7
    SpringMVC(十二):SpringMVC 处理输出模型数据之@ModelAttribute
    oracle之 redo过高诊断
    oracle之 手动创建 emp 表 与 dept 表
    oracle之 11.2.0.4 bbed安装
    oracle12c之 控制pdb中sga 与 pga 内存使用
    storm之 Storm 工作原理
    spark之 spark 2.2.0 Standalone安装、wordCount演示
    hadoop之 参数调优
  • 原文地址:https://www.cnblogs.com/wgscd/p/7762642.html
Copyright © 2011-2022 走看看