본문 바로가기
Unity

Unity AVPro HLS Streaming Player 기능 Seeking

by OK강프로 2024. 6. 24.
반응형

Unity로 만든 앱에서 AVPro플러그인을 구매해서, HLS Streaming playback기능을 구현했습니다.

비디오 플레이어의 대표 기능 중 Player's Seek 기능을 구현하는 과정에서 AVPro가 제공하는 Event API들을 이용했습니다. 

MediaPlayer, Seek 이 수행될대 불리는 StartedSeek에서부터 Seek기능이 수행완료 되면 불리는 FinisedSeeking Event을 이용해서 구현을 완료했습니다. 

_mediaPlayer.Events.AddListener(HandleEvent);
void HandleEvent(MediaPlayer mp, MediaPlayerEvent.EventType eventType, ErrorCode code)
		{
			Debug.Log("[SongPlayer] MediaPlayer " + mp.name + " generated event: " + eventType.ToString());
			if (eventType == MediaPlayerEvent.EventType.Error)
            {
                PopupManager.Instance.LoadPopup(!SSMembershipUtils.IsEnableInternet()
                    ? CommonConstant.PopupNetwork
                    : CommonConstant.PopupError); // 에러 팝업
                
                Debug.LogError("SongPlayer MediaPlayer Error: " + code);
            }
			else if (eventType == MediaPlayerEvent.EventType.FinishedSeeking)
			{
				_isHoveringOverTimeline = false;
				Debug.LogError("SongPlayer FinishedSeeking: " + code);
			}
			else if (eventType == MediaPlayerEvent.EventType.StartedSeeking)
			{
				Debug.LogError("SongPlayer StartedSeeking: " + code);
			}
			else if (eventType == MediaPlayerEvent.EventType.StartedBuffering)
			{
				Debug.LogError("SongPlayer StartedBuffering: " + code);
			} else if (eventType == MediaPlayerEvent.EventType.FinishedBuffering)
			{
				Debug.LogError("SongPlayer FinishedBuffering: " + code);
			} else if (eventType == MediaPlayerEvent.EventType.Started)
			{
				Debug.LogError("SongPlayer  Started: " + code);
				isPlaying = true;

				if (isFinished)
				{
					_mediaPlayer.Pause();
					isFinished = false;
				}

			} else if (eventType == MediaPlayerEvent.EventType.Stalled)
            {
				if(!SSMembershipUtils.IsEnableInternet()) {
					PopupManager.Instance.LoadPopup(CommonConstant.PopupNetwork);
				}

            } else if (eventType == MediaPlayerEvent.EventType.Closing)
			{
				Debug.LogError(" Closing: " + code);
			} else if (eventType == MediaPlayerEvent.EventType.ReadyToPlay)
			{
				Debug.LogError(" ReadyToPlay: " + code);
			} else if (eventType == MediaPlayerEvent.EventType.FirstFrameReady)
            {
                PopupManager.Instance.ReleasePopup();
                Debug.LogError(" FirstFrameReady: " + code);
            } else if (eventType == MediaPlayerEvent.EventType.FinishedPlaying)
            {
	            Debug.LogError("  MediaPlayerEvent.EventType.FinishedPlaying " + code);

	            ResetUI();
	            
	            var framework = FindObjectOfType<PlayerFramework>();   // 칭찬모션 띄움
                if(framework) framework.ShowEnding();
                
                if(!ActivityNavigator.Instance.IsLearningPath) return;
                ActivityProgressManager.Instance.SaveStarCount();      // 진척도 저장

                isFinished = true;
                
                Debug.LogError("FinishedPlaying: " + code);
            }      
			
		}

 

이외에도 다양한 플레이어 관련 Event Callback API를 제공합니다. 

https://www.renderheads.com/content/docs/AVProVideo/articles/feature-events.html

반응형