public iOSVideoPlayer() { this.ToolbarItems.Add (new ToolbarItem { Text = "Actions", Command = new Command (async () => { var result = await DisplayActionSheet("Select", "Cancel", null, "Full UIScreen", "Full Screen", "Fit Screen", "Restart", "Play", "Stop", "Resize", "Pause", "StatusBar Hide"); if (result == "Full UIScreen") { // this uiscreen.MainScreen.Bounds this.player.VideoPlayer.ContentHeight = -1; this.player.VideoPlayer.ContentWidth = -1; } else if (result == "Full Screen") { // this goes to full device screen player.VideoPlayer.FullScreen = !player.VideoPlayer.FullScreen; } else if (result == "Fit Screen") { player.VideoPlayer.FitInWindow = !player.VideoPlayer.FitInWindow; } else if (result == "Restart") { this.player.VideoPlayer.Seek = 0; } else if (result == "Play") { this.player.VideoPlayer.PlayerAction = VideoSamples.Library.VideoState.PLAY; } else if (result == "Stop") { this.player.VideoPlayer.PlayerAction = VideoSamples.Library.VideoState.STOP; } else if (result == "Resize") { if (test == 0) { this.player.HeightRequest = 400; this.player.VideoPlayer.ContentHeight = 400; } else if (test == 1) { this.player.HeightRequest = 200; this.player.VideoPlayer.ContentHeight = 100; } else if (test == 2) { this.player.HeightRequest = 100; this.player.VideoPlayer.ContentHeight = 100; test = -1; } test++; } else if (result == "Pause") { this.player.VideoPlayer.PlayerAction = VideoSamples.Library.VideoState.PAUSE; } else if (result == "StatusBar Hide") { this.player.VideoPlayer.ActionBarHide = !this.player.VideoPlayer.ActionBarHide; } }) }); player = new VideoPlayerView(); player.HeightRequest = 200; player.VideoPlayer.AddVideoController = true; player.VideoPlayer.FileSource = "sample.m4v"; //"http://192.168.202.78/sample.m4v"; // autoplay video player.VideoPlayer.AutoPlay = true; this.Content = new StackLayout { VerticalOptions = LayoutOptions.StartAndExpand, Spacing = 0, Padding = new Thickness(0,0), Children = { player } }; }
public AndroidVideoPlayer () { player = new VideoPlayerView (); this.ToolbarItems.Add (new ToolbarItem { Order = ToolbarItemOrder.Secondary, Text = "Controller", Command = new Command( () => { this.player.VideoPlayer.AddVideoController = !this.player.VideoPlayer.AddVideoController; }) }); this.ToolbarItems.Add (new ToolbarItem { Order = ToolbarItemOrder.Secondary, Text = "Full Screen", Command = new Command( () => { // resize the Content for full screen mode this.player.VideoPlayer.FullScreen = !this.player.VideoPlayer.FullScreen; if (this.player.VideoPlayer.FullScreen) { this.player.HeightRequest = -1; this.Content.VerticalOptions = LayoutOptions.FillAndExpand; player.VideoPlayer.FullScreen = true; } else { this.player.HeightRequest = 200; this.Content.VerticalOptions = LayoutOptions.StartAndExpand; player.VideoPlayer.FullScreen = false; } }) }); this.ToolbarItems.Add (new ToolbarItem { Order = ToolbarItemOrder.Secondary, Text = "Play", Command = new Command( () => { this.player.VideoPlayer.PlayerAction = VideoSamples.Library.VideoState.PLAY; }) }); this.ToolbarItems.Add (new ToolbarItem { Order = ToolbarItemOrder.Secondary, Text = "Stop", Command = new Command( () => { this.player.VideoPlayer.PlayerAction = VideoSamples.Library.VideoState.STOP; }) }); this.ToolbarItems.Add (new ToolbarItem { Order = ToolbarItemOrder.Secondary, Text = "Pause", Command = new Command( () => { this.player.VideoPlayer.PlayerAction = VideoSamples.Library.VideoState.PAUSE; }) }); this.ToolbarItems.Add (new ToolbarItem { Order = ToolbarItemOrder.Secondary, Text = "Restart", Command = new Command( () => { this.player.VideoPlayer.PlayerAction = VideoSamples.Library.VideoState.RESTART; }) }); // heightRequest must be set it not full screen player.HeightRequest = 200; player.VideoPlayer.AddVideoController = false; // location in Assets folder. file marked as Asset, NOT Resource player.VideoPlayer.FileSource = "sample"; // autoplay video //player.VideoPlayer.AutoPlay = true; this.Content = new StackLayout { VerticalOptions = LayoutOptions.StartAndExpand, Children = { player } }; }