2.2.0 • Published 5 years ago
com.adrenak.mediaplayer v2.2.0
MediaPlayer
A standardised media player interface for Unity. Aimed largely towards being able to make video player UI without worrying about the underlying video player.
Media Playback
The IVideoPlayer interface
Properties
TextureTheTextureobject that represents the texture on which the video playsIsReadyIf the video player has loaded the video and the video can be played or notIsPlayingIf the video is presently playing. False when the video is not loaded or paused.DurationThe duration of the video in aTimeSpanobjectTotalFramesTotal number of frames in the video that has been loadedFrameRateRate of frame playback in frames per second of the loaded videoCurrentFrameThe currently showing frame in the video playerCurrentPositionThe normalized position of the current frame in the 0,1 ranngeCurrentTimeSpanThe time gap between the video start and the current frame showing
Methods
Open(string path, bool autoPlay)Opens a video for loading via the path.autoPlayflag decides if the video playback should start immediately after successful loading.PlayStarts playing/resumes the videoPausePauses the video playbackStopStop the video playbackSeekFrame(long frame)Seeks the playback to the given frame from the start of the videoSeekTimeSpan(TimeSpan timeSpan)Seeks the playback to a frametimeSpanduration from the start of the videoSeekPosition(float position)Seeks the playabck to a framepositionpercentage from the start of the video. Eg. .5f seeks it to the middle of the videoJumpFrames(long frameDelta)Seeks to a frameframeDeltaframes away from the current frameJumpTimeSpan(TimeSpan timeSpanDelta)Seeks to a frametimeSpanDeltaduration away from the current frameJumpPosition(float positionDelta)Seeks to a framepositionDeltapercentage from the current frame. Eg. -25f whenCurrentPositionis .75f will take it to the middle of the video
Events
OnReadyFired when a video is loaded and it capable of being playerOnErrorFired when there is an error in loading the videoOnPlayFired when the video starts playing for the first time or is resumed in the middle of the playbackOnPauseFired when the video is pausedOnStopFired when the playback is stoppedOnSeekFired when the media player seeks to another frameOnJumpFired when the media played jumps forward or backward by any number of frames
Subtitles
Subtitle related code is a modified version of @roguecode's Unity-Simple-SRT on GitHub.
The SubtitleBlock class
Properties
IndexThe Index of the block in the subtitle file.LengthThe duration of the subtitle block in secondsFromThe moment the subtitles should start displayingToThe moment the subtitles should stop displayingTextThe text to be displayed
The ISubtitlesParser interface
Methods
GetByTime(double time)Returns the subtitle block from the subtitle file at the specified time
Notes
The project contains the following:
IVideoPlayer: An implementation for Unity's VideoPlayer component. Please seeSampleMediaPlayerunderSamples/SRTParser: An implementation ofISubtitlesParserfor working withSRTsubtitle format.SubtitleDisplayer: A simple UI for showing the subtitles that requires an instance ofISubstitlesParser