2017-06-06 135 views
1

我對Xamarin很新穎...Xamarin Forms視頻播放器(MediaManager插件)

我試圖創建一個類似於應用的YouTube。我不知道如何在我的應用程序內播放視頻。我試圖使用MediaManager插件https://github.com/martijn00/XamarinMediaManager,但根本無法弄清楚。

如果任何人都可以建議一個不同的插件,或者詳細解釋如何使用MediaManager插件,那就太棒了。

該插件的文檔是殘暴的,我根本無法理解它。

繼承人我到目前爲止:我只是試圖通過按鈕點擊播放視頻。

XAML文件:

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="App2.Video_Play_Page" 
     Title="Video_Play_Page" 
     BackgroundColor="#4B1388"> 
<ContentPage.Content> 
    <StackLayout Padding="10, 10, 10, 10"> 

     <Label Text="video Player..." /> 

     <Button Clicked="PlayVideo" Text="Play me!"/> 
    </StackLayout> 
</ContentPage.Content> 

Xaml.cs文件:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

using Xamarin.Forms; 
using Xamarin.Forms.Xaml; 

using Plugin.MediaManager; 

namespace App2 
{ 
[XamlCompilation(XamlCompilationOptions.Compile)] 
public partial class Video_Play_Page : ContentPage 
{ 
    public Video_Play_Page() 
    { 
     InitializeComponent(); 
    } 

    private void PlayVideo(object sender, EventArgs e) 
    { 
     CrossMediaManager.Current.Play("https://www.youtube.com/watch?v=Gm8bQxnold0"); 
    } 
} 
} 

注:我不知道我是否已經正確安裝了一切。如果有人能解釋一下,那也會很棒。

+1

會[此答案](https://stackoverflow.com/a/44522846/7196681)有幫助嗎? – Curiousity

回答

0

您可以檢查出的視頻播放器組件。它允許您在iOS,Android和Windows Phone上呈現原生視頻播放器。下面的代碼片段顯示了將其放入並使用它的最簡單示例。您還可以連接到播放,暫停,停止,完成等事件。您可以控制音量,自動播放以及重複播放其他內容。

https://github.com/adamfisher/Xamarin.Forms.VideoPlayer

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:o="clr-namespace:Octane.Xam.VideoPlayer;assembly=Octane.Xam.VideoPlayer" 
      x:Class="VideoPlayerSamples.VideoPlayerBasicExamplePage" 
      Title="Basic Video Player"> 

    <o:VideoPlayer Source="http://vjs.zencdn.net/v/oceans.mp4" /> 

</ContentPage> 

免責聲明:這是我的組件。