int effectDuration = 200;
/// <summary>
- /// A flag that whether the button is handling clicked event or not
- /// </summary>
- private static bool isButtonRunning = false;
-
- /// <summary>
/// Gets or sets MediaHubButtonIcon's image source
/// </summary>
public string MediaHubButtonIcon
/// </summary>
private void InitializeButton()
{
- Btn.Clicked += async (s, e) =>
+ Btn.Clicked += (s, e) =>
{
- if (isButtonRunning)
- {
- return;
- }
-
- isButtonRunning = true;
-
Clicked?.Invoke(this, EventArgs.Empty);
-
- try
- {
- BtnIcon.Source = PressedImage;
-#pragma warning disable CS4014
- BG.ScaleTo(0.1, Convert.ToUInt32(effectDuration), Easing.CubicInOut);
-#pragma warning restore CS4014
- await BG.FadeTo(0, Convert.ToUInt32(effectDuration), Easing.CubicInOut);
-
- BtnIcon.Source = NormalImage;
-#pragma warning disable CS4014
- BG.ScaleTo(1, Convert.ToUInt32(effectDuration), Easing.CubicInOut);
-#pragma warning restore CS4014
- await BG.FadeTo(1, Convert.ToUInt32(effectDuration), Easing.CubicInOut);
- }
- catch (Exception err)
- {
- DbgPort.D("Error : " + err.Message);
- }
-
- isButtonRunning = false;
+ var BGScale = BG.Scale;
+ var BGOpacity = BG.Opacity;
+
+ this.AbortAnimation("ClickAnimation");
+ BtnIcon.Source = PressedImage;
+ this.Animate("ClickAnimation", (v) =>
+ {
+ BG.Scale = BGScale - (BGScale - 0.1) * v;
+ BG.Opacity = BGOpacity - (BGOpacity - 0) * v;
+ },
+ length: Convert.ToUInt32(effectDuration),
+ easing: Easing.CubicInOut,
+ finished: (progress, isCanceled) =>
+ {
+ BtnIcon.Source = NormalImage;
+ if (!isCanceled)
+ {
+ this.Animate("ClickAnimation", (v) =>
+ {
+ BG.Scale = 0.1 + 0.9 * v;
+ BG.Opacity = v;
+ },
+ length: Convert.ToUInt32(effectDuration),
+ easing: Easing.CubicInOut,
+ finished: (progress2, isCanceled2) =>
+ {
+ BG.Scale = 1;
+ BGOpacity = 1;
+ });
+ }
+ else
+ {
+ BG.Scale = 1;
+ BGOpacity = 1;
+ }
+ });
};
}
public ICommand SelectAllContentCommand { get; set; }
/// <summary>
+ /// A command for changing current video to next
+ /// </summary>
+ public ICommand SetNextVideoCommand { get; set; }
+
+ /// <summary>
+ /// A command for changing current video to previous
+ /// </summary>
+ public ICommand SetPrevVideoCommand { get; set; }
+
+ /// <summary>
/// A command to set current video information
/// </summary>
public ICommand SetCurrentVideoInfo
/// Gets or sets the MediaInformation of current video
/// </summary>
public MediaInformation CurrentVideo { get; set; }
+ public int CurrentVideoIndex { get; set; }
+ public List<MediaInformation> PlayList { get; set; }
+
+ public bool IsLastVideo {
+ get
+ {
+ return (PlayList.Count - 1) == CurrentVideoIndex;
+ }
+ }
/// <summary>
/// Gets or sets the DeleteStatus
InitializeCommands();
VideoList = new ObservableCollection<GroupItem>();
SelectedList = new List<MediaInformation>();
+ PlayList = new List<MediaInformation>();
+
OnPropertyChanged("VideoList");
MediaHubImpl.GetInstance.VideoProviderInstance.SetContentUpdatedEventListener((sender, arg) =>
{
OnPropertyChanged("SelectedCount");
});
+
+ SetNextVideoCommand = new Command(() =>
+ {
+ SetNextVideo();
+ });
+
+ SetPrevVideoCommand = new Command(() =>
+ {
+ SetPrevVideo();
+ });
+ OnPropertyChanged("SetNextVideoCommand");
+ OnPropertyChanged("SetPrevVideoCommand");
+
OnPropertyChanged("ChangeTabStatusCommand");
OnPropertyChanged("ChangeSortOptionCommand");
}
//await Task.Delay(1);
VideoList.Add(group);
}
+
+ foreach (var group in VideoList)
+ {
+ foreach (var item in group.Contents)
+ {
+ PlayList.Add(item.Information);
+ }
+ }
}
/// <summary>
private void SetCurrentVideo(MediaInformation videoContent)
{
CurrentVideo = videoContent;
+ CurrentVideoIndex = PlayList.IndexOf(CurrentVideo);
OnPropertyChanged("CurrentVideo");
}
/// <summary>
+ /// A method for setting the next video
+ /// </summary>
+ private void SetPrevVideo()
+ {
+ if (CurrentVideoIndex != 0)
+ {
+ CurrentVideoIndex--;
+ CurrentVideo = PlayList[CurrentVideoIndex];
+ OnPropertyChanged("CurrentVideo");
+ }
+ }
+
+ /// <summary>
+ /// A method for setting the next video
+ /// </summary>
+ private void SetNextVideo()
+ {
+ if (CurrentVideoIndex != (PlayList.Count - 1))
+ {
+ CurrentVideoIndex++;
+ CurrentVideo = PlayList[CurrentVideoIndex];
+ OnPropertyChanged("CurrentVideo");
+ }
+ }
+
+ /// <summary>
/// A method for setting latest played time of the media file.
/// </summary>
/// <param name="videoContent">A played media file</param>
using Extension = Tizen.Xamarin.Forms.Extension;
using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
using System.Threading;
+using System.Windows.Input;
namespace TVMediaHub.Tizen.Views
{
AUTO,
};
+ enum PlayStatus
+ {
+ Play = 0,
+ Rewind,
+ FastFoward,
+ Pause
+ }
+
/// <summary>
/// The media duration in Milliseconds.
/// </summary>
private int timerDueTime = 5000;
/// <summary>
- /// Gets or sets whether play status is back forward or back rewind
+ /// Gets or sets current play status
/// </summary>
- private bool IsInPlayBackRewFwd
- {
- set
- {
- if (value == false)
- {
- PlayBackForwardIndex = 0;
- PlayBackRewindIndex = 0;
- }
- }
-
- get
- {
- if (PlayBackForwardIndex == 0 &&
- PlayBackRewindIndex == 0)
- {
- return false;
- }
-
- return true;
- }
- }
+ private PlayStatus CurrentPlayStatus { get; set; }
/// <summary>
/// The value for play back forward index
}
/// <summary>
+ /// Identifies the SetNextVideoCommand bindable property
+ /// </summary>
+ public static readonly BindableProperty SetNextVideoCommandProperty = BindableProperty.Create("SetNextVideoCommand", typeof(ICommand), typeof(VideoPlayer), null);
+
+ /// <summary>
+ /// A Command for setting current video to next video
+ /// </summary>
+ public ICommand SetNextVideoCommand
+ {
+ get { return (ICommand)GetValue(SetNextVideoCommandProperty); }
+ set { SetValue(SetNextVideoCommandProperty, value); }
+ }
+
+ /// <summary>
+ /// Identifies the SetPrevVideoCommand bindable property
+ /// </summary>
+ public static readonly BindableProperty SetPrevVideoCommandProperty = BindableProperty.Create("SetPrevVideoCommand", typeof(ICommand), typeof(VideoPlayer), null);
+
+ /// <summary>
+ /// A Command for setting current video to previous video
+ /// </summary>
+ public ICommand SetPrevVideoCommand
+ {
+ get { return (ICommand)GetValue(SetPrevVideoCommandProperty); }
+ set { SetValue(SetPrevVideoCommandProperty, value); }
+ }
+
+ /// <summary>
/// A constructor
/// </summary>
public VideoPlayer()
BindingContext = VideoTabViewModelLocator.ViewModel;
InitializeComponent();
InitializeFontSize();
-
+ PropertyChanged += VideoPlayePropertyChanged;
mediaView = new Extension.MediaView();
mediaView.NativeViewCreated += (s, e) =>
}
#pragma warning disable CS4014
- GradientDim.FadeTo(0, 667, Easing.CubicInOut);
+ GradientDim.FadeTo(0, 667, Easing.CubicInOut);
ControlArea.TranslateTo(0, 93, 667, Easing.CubicInOut);
ControlArea.FadeTo(0, 667, Easing.CubicInOut);
TitleLabel.TranslateTo(0, -50, 667, Easing.CubicInOut);
await TitleLabel.FadeTo(0, 667, Easing.CubicInOut);
App.AppMainPage.Navigation.PopAsync();
- //Program.TransitionToMain(0);
#pragma warning restore CS4014
- };
+ };
+ }
+
+ /// <summary>
+ /// This method is called when the properties is changed
+ /// </summary>
+ /// <param name="sender">The source of the event</param>
+ /// <param name="e">A propertyChanged event argument</param>
+ private void VideoPlayePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName.Equals("CurrentVideo"))
+ {
+ if (playerInstance.State == PlayerState.Playing || playerInstance.State == PlayerState.Paused)
+ {
+ try
+ {
+ playerInstance.Stop();
+ playerInstance.Unprepare();
+ playerDisplayInstance = new Display((MediaView)mediaView.NativeView);
+ playerInstance.Display = playerDisplayInstance;
+ videoMediaSource = new MediaUriSource(CurrentVideo.FilePath);
+ playerInstance.SetSource(videoMediaSource);
+ }
+ catch (Exception ex)
+ {
+ DbgPort.D(ex.Message);
+ return;
+ }
+ PrepareAsync();
+ }
+ }
}
/// <summary>
int playPosition = playerInstance.GetPlayPosition();
SetPlayTime(playPosition);
progress.Progress = (double)playPosition / sourceDuration;
- DbgPort.D("Status : " + playerInstance.State + "/" + prevPlayerStatus + ", temp : " + playPosition + ", progress : " + progress.Progress.ToString());
+ //DbgPort.D("Status : " + playerInstance.State + "/" + prevPlayerStatus + ", temp : " + playPosition + ", progress : " + progress.Progress.ToString());
if (prevPlayerStatus != playerInstance.State)
{
if (playerInstance.State == PlayerState.Paused || playerInstance.State == PlayerState.Ready)
{
- if (IsInPlayBackRewFwd)
+ if (CurrentPlayStatus == PlayStatus.Rewind || CurrentPlayStatus == PlayStatus.FastFoward)
{
- IsInPlayBackRewFwd = false;
playerInstance.SetPlaybackRate((PlayBackRate[0]));
}
prevPlayerStatus = playerInstance.State;
}
-
- // TODO : check later, hotfix for VD GBM player
- if ((PlayBackRewindIndex != 0 && playPosition < 4000)
- || PlayBackForwardIndex != 0 && playPosition > (sourceDuration - 6000))
- {
- IsInPlayBackRewFwd = false;
- playerInstance.SetPlaybackRate((PlayBackRate[0]));
-
- if (SpeedInfo.Opacity == 1)
- {
- SpeedInfo.FadeTo(0.0, 100);
- }
- }
});
if (playerInstance.State != PlayerState.Playing &&
playerInstance.Display = playerDisplayInstance;
playerInstance.PlaybackCompleted += (obj, eventArg) =>
{
+ PlayBackRewindIndex = 0;
+ PlayBackForwardIndex = 0;
DbgPort.D("PlaybackCompleted");
- try
+
+ if (CurrentPlayStatus == PlayStatus.Rewind)
{
- playerInstance.Stop();
- playerInstance.Unprepare();
+ try
+ {
+ CurrentPlayStatus = PlayStatus.Play;
+ playerInstance?.SetPlaybackRate(1);
+ playerInstance?.Start();
+ }
+ catch (Exception ex)
+ {
+ DbgPort.E("Start Failed : " + ex.Message);
+ return;
+ }
}
- catch (Exception ex)
+ else if (VideoTabViewModelLocator.ViewModel.IsLastVideo)
{
- DbgPort.E("Stop Failed : " + ex.Message);
+ App.AppMainPage.Navigation.PopAsync();
+ }
+ else
+ {
+ try
+ {
+ CurrentPlayStatus = PlayStatus.Play;
+ SetNextVideoCommand?.Execute("");
+ }
+ catch (Exception ex)
+ {
+ DbgPort.E("Stop Failed : " + ex.Message);
+ }
}
-
- PausePlayBtn.NormalImage = PausePlayBtn.NormalImage.Replace("pause", "play");
- PausePlayBtn.PressedImage = PausePlayBtn.PressedImage.Replace("pause", "play");
- PausePlayBtn.MediaHubButtonIcon = PausePlayBtn.NormalImage;
-
- // If you don't want to back automatically whenever VideoPlayer's play is over, remove below line.
- // TODO: Remove this later, only for TDC
- Navigation.PopToRootAsync();
};
videoMediaSource = new MediaUriSource(CurrentVideo.FilePath);
/// </summary>
private void PlayVideo()
{
- DbgPort.D("ElmSharp.Window is activated");
-
try
{
playerInstance.Start();
/// <param name="e">An event's argument</param>
private async void PreviousBtnClicked(object sender, EventArgs e)
{
+ if (playerInstance.State == PlayerState.Idle || playerInstance.State == PlayerState.Preparing)
+ {
+ return;
+ }
+
if (ControlArea.Opacity == 0)
{
SetControlAreaState(ControlAreaState.AUTO);
SetControlAreaState(ControlAreaState.AUTO);
- try
- {
- await playerInstance.SetPlayPositionAsync(0, true);
- }
- catch (Exception ex)
+ if (playerInstance.GetPlayPosition() < 1000)
{
- DbgPort.E("SetPlayPositionAsync Failed : " + ex.Message);
+ SetPrevVideoCommand?.Execute("");
return;
}
+ else
+ {
+ try
+ {
+ await playerInstance.SetPlayPositionAsync(0, true);
+ }
+ catch (Exception ex)
+ {
+ DbgPort.E("SetPlayPositionAsync Failed : " + ex.Message);
+ return;
+ }
- progress.Progress = 0.0;
+ progress.Progress = 0.0;
+ }
}
/// <summary>
*/
try
{
+ CurrentPlayStatus = PlayStatus.Rewind;
PlayBackRewindIndex++;
playerInstance.SetPlaybackRate((PlayBackRate[PlayBackRewindIndex]) * -1);
// TODO : check later, added as hotfix for VD GBM player
if (playerInstance.State == PlayerState.Paused || playerInstance.State == PlayerState.Ready)
{
SetControlAreaState(ControlAreaState.SHOW);
+ CurrentPlayStatus = PlayStatus.Play;
PlayVideo();
}
else if (playerInstance.State == PlayerState.Playing)
try
{
+ CurrentPlayStatus = PlayStatus.Pause;
playerInstance.Pause();
}
catch (Exception ex)
try
{
+ CurrentPlayStatus = PlayStatus.FastFoward;
PlayBackForwardIndex++;
playerInstance.SetPlaybackRate(PlayBackRate[PlayBackForwardIndex]);
// TODO : check later, added as hotfix for VD GBM player
/// <param name="e">An event's argument</param>
private async void NextBtnClicked(object sender, EventArgs e)
{
+ if (playerInstance.State == PlayerState.Idle || playerInstance.State == PlayerState.Preparing)
+ {
+ return;
+ }
+
if (ControlArea.Opacity == 0)
{
SetControlAreaState(ControlAreaState.AUTO);
SetControlAreaState(ControlAreaState.AUTO);
- try
+ if (playerInstance.GetPlayPosition() > sourceDuration - 1000)
{
- await playerInstance.SetPlayPositionAsync(sourceDuration - 500, true);
+ SetNextVideoCommand?.Execute("");
}
- catch (Exception err)
+ else
{
- DbgPort.E("SetPlayPositionAsync Failed : " + err.Message);
- return;
+ try
+ {
+ await playerInstance.SetPlayPositionAsync(sourceDuration - 1000, true);
+ }
+ catch (Exception err)
+ {
+ DbgPort.E("SetPlayPositionAsync Failed : " + err.Message);
+ return;
+ }
+
}
progress.Progress = 1.0;
TitleLabel.TranslateTo(0, 0, 667, Easing.CubicInOut);
TitleLabel.FadeTo(1, 667, Easing.CubicInOut);
- if (IsInPlayBackRewFwd)
+ if (CurrentPlayStatus == PlayStatus.Rewind || CurrentPlayStatus == PlayStatus.FastFoward)
{
SpeedInfo.FadeTo(1.0, 100);
}