Class MediaPlayer
Media player class for playing Audio, Image and Video.
媒體播放器類別,用於播放音訊、影像及視訊。
Inheritance
Namespace: Votanic.vMedia.MediaPlayer
Assembly: Votanic.vMedia.dll
Syntax
[AddComponentMenu("")]
public class MediaPlayer : MonoBehaviour
Fields
audios
Audios loaded.
已載入的音訊。
Declaration
public Dictionary<int, List<AudioSource>> audios
Field Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.Int32, System.Collections.Generic.List<UnityEngine.AudioSource>> |
autoNext
Auto open next media if true.
當 true 時自動跳到下一個媒體。
Declaration
[Tooltip("Auto open next media.\n自動跳到下一個媒體。")]
public bool autoNext
Field Value
Type | Description |
---|---|
System.Boolean |
autoNextButton
Raw Image elements of Auto Next button.
自動跳至下一個媒體按鈕的 Raw Image 元素。
Declaration
[Tooltip("Raw Image elements of Auto Next button.\n自動跳至下一個媒體按鈕的 Raw Image 元素。")]
public List<RawImage> autoNextButton
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.UI.RawImage> |
autoNextTexture
Textures for Auto Next state.
自動跳至下一個媒體狀態的紋理。
Declaration
[Tooltip("Textures for Auto Next state.\n自動跳至下一個媒體狀態的紋理。")]
public List<Texture2D> autoNextTexture
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Texture2D> |
autoPlay
Auto play media if true.
當 true 時自動播放媒體。
Declaration
[Tooltip("Auto play media.\n自動播放媒體。")]
public bool autoPlay
Field Value
Type | Description |
---|---|
System.Boolean |
autoPlayButton
Raw Image elements of Auto Play button.
自動播放按鈕的 Raw Image 元素。
Declaration
[Tooltip("Raw Image elements of Auto Play button.\n自動播放按鈕的 Raw Image 元素。")]
public List<RawImage> autoPlayButton
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.UI.RawImage> |
autoPlayTexture
Textures for Auto Play state.
自動播放狀態的紋理。
Declaration
[Tooltip("Textures for Auto Play state.\n自動播放狀態的紋理。")]
public List<Texture2D> autoPlayTexture
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Texture2D> |
current
The current medium.
目前媒體。
Declaration
[Tooltip("The current medium index.\n目前媒體編號。")]
public int current
Field Value
Type | Description |
---|---|
System.Int32 |
defaultTexture
Default texture display on UI or Mesh attached.
預設的顯示紋理。
Declaration
[Tooltip("Default texture display on UI or Mesh attached.\n預設的顯示紋理。")]
public Texture2D defaultTexture
Field Value
Type | Description |
---|---|
UnityEngine.Texture2D |
duration
Duration of current medium.
目前媒體的長度。
Declaration
[Tooltip("Duration of current medium.\n目前媒體的長度。")]
public float duration
Field Value
Type | Description |
---|---|
System.Single |
fileLocation
The relative folder location of files.
檔案的相對文件夾位置。
Declaration
[Header("[Settings]")]
[Tooltip("The relative folder location of files.\n檔案的相對文件夾位置。")]
public FileLocation fileLocation
Field Value
Type | Description |
---|---|
FileLocation |
ignoreList
The media list wanted to be ignored in current launch.
在當前啟動中希望被忽略的媒體列表。
Declaration
[Tooltip("The media list wanted to be ignored in current launch.\n在當前啟動中希望被忽略的媒體列表。")]
public string ignoreList
Field Value
Type | Description |
---|---|
System.String |
images
Images loaded.
已載入的影像。
Declaration
[Tooltip("Images loaded.\n已載入的影像。")]
public List<Texture2D> images
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Texture2D> |
initialized
Return true if media player is initialized.
當媒體播放器初始化後傳回 true。
Declaration
[Header("[Status]")]
[Tooltip("Initialization state.\n初始化狀態。")]
public bool initialized
Field Value
Type | Description |
---|---|
System.Boolean |
isFinished
Return true if the media player is totally finished playing.
當媒體播放器完全播放結束時傳回 true。
Declaration
[Tooltip("Finished state.\n完成狀態。")]
public bool isFinished
Field Value
Type | Description |
---|---|
System.Boolean |
isPaused
Return true if the media player is paused.
當媒體播放器暫停時傳回 true。
Declaration
[Tooltip("Paused state.\n暫停狀態。")]
public bool isPaused
Field Value
Type | Description |
---|---|
System.Boolean |
isPlaying
Return true if the media player is playing.
當媒體播放器播放時傳回 true。
Declaration
[Tooltip("Playing state.\n播放狀態。")]
public bool isPlaying
Field Value
Type | Description |
---|---|
System.Boolean |
loop
Loop setting of media player.
媒體播放器的循環設定。
Declaration
[Tooltip("Loop setting of media player.\n媒體播放器的循環設定。")]
public Loop loop
Field Value
Type | Description |
---|---|
Loop |
loopButton
Raw Image elements of Loop button.
循環按鈕的 Raw Image 元素。
Declaration
[Tooltip("Raw Image elements of Loop button.\n循環按鈕的 Raw Image 元素。")]
public List<RawImage> loopButton
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.UI.RawImage> |
loopTexture
Textures for Loop state.
循環狀態的紋理。
Declaration
[Tooltip("Textures for Loop state.\n循環狀態的紋理。")]
public List<Texture2D> loopTexture
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Texture2D> |
media
List of media.
媒體列表。
Declaration
[Tooltip("List of media.\n媒體列表。")]
public List<Media> media
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<Media> |
mute
Mute media player if true.
當 true 時把媒體靜音。
Declaration
[Tooltip("Mute media player.\n把媒體靜音。")]
public bool mute
Field Value
Type | Description |
---|---|
System.Boolean |
muteButton
Raw Image elements of Mute button.
靜音按鈕的 Raw Image 元素。
Declaration
[Tooltip("Raw Image elements of Mute button.\n靜音按鈕的 Raw Image 元素。")]
public List<RawImage> muteButton
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.UI.RawImage> |
muteTexture
Textures for Mute state.
靜音狀態的紋理。
Declaration
[Tooltip("Textures for Mute state.\n靜音狀態的紋理。")]
public List<Texture2D> muteTexture
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Texture2D> |
playPauseButton
Raw Image elements of Play Pause button.
播放及暫停按鈕的 Raw Image 元素。
Declaration
[Tooltip("Raw Image elements of Play Pause button.\n播放及暫停按鈕的 Raw Image 元素。")]
public List<RawImage> playPauseButton
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.UI.RawImage> |
playPauseTexture
Textures for Play Pause state.
播放及暫停狀態的紋理。
Declaration
[Tooltip("Textures for Play Pause state.\n播放及暫停狀態的紋理。")]
public List<Texture2D> playPauseTexture
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Texture2D> |
random
Randomly play media.
隨機播放媒體。
Declaration
[Tooltip("Randomly play media.\n隨機播放媒體。")]
public bool random
Field Value
Type | Description |
---|---|
System.Boolean |
randomButton
Raw Image elements of Random button.
隨機按鈕的 Raw Image 元素。
Declaration
[Tooltip("Raw Image elements of Random button.\n隨機按鈕的 Raw Image 元素。")]
public List<RawImage> randomButton
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.UI.RawImage> |
randomTexture
Textures for Random state.
隨機狀態的紋理。
Declaration
[Tooltip("Textures for Random state.\n隨機狀態的紋理。")]
public List<Texture2D> randomTexture
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Texture2D> |
renderers
The mesh of objects used to display media.
用作顯示媒體的物件 Mesh。
Declaration
[Header("[Components]")]
[Tooltip("The renderer of objects used to display media.\n用作顯示媒體的物件渲染器。")]
public List<Renderer> renderers
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Renderer> |
time
Current time of medium.
媒體目前時間。
Declaration
[Tooltip("Current time of medium.\n媒體目前時間。")]
public double time
Field Value
Type | Description |
---|---|
System.Double |
timeBar
Image elements to display time duration percentage.
Image 元素用於顯示時間及總長度百分比。
Declaration
[Tooltip("Image elements to display time duration percentage.\nImage 元素用於顯示時間及總長度百分比。")]
public List<Image> timeBar
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.UI.Image> |
timeControl
Time control element.
時間控制元素。
Declaration
[Tooltip("Time control element.\n時間控制元素。")]
public SliderControl timeControl
Field Value
Type | Description |
---|---|
SliderControl |
timeDuration
String of time and duration.
時間及長度字串。
Declaration
[Tooltip("String of time and duration.\n時間及長度字串。")]
public string timeDuration
Field Value
Type | Description |
---|---|
System.String |
timeText
Text elements to display time and duration.
Text 元素用於顯示時間及總長度。
Declaration
[Header("[Player UI]")]
[Tooltip("Text elements to display time and duration.\nText 元素用於顯示時間及總長度。")]
public List<Text> timeText
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.UI.Text> |
uiElements
The UI raw images used to display media.
用作顯示媒體的 UI Raw Image 組件。
Declaration
[Tooltip("The UI raw images used to display media.\n用作顯示媒體的 UI Raw Image 組件。")]
public List<RawImage> uiElements
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.UI.RawImage> |
videos
Video preview images.
視訊預覽影像。
Declaration
[Tooltip("Video preview images.\n視訊預覽影像。")]
public List<Texture2D> videos
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.Texture2D> |
volume
Volume of media player.
媒體播放器音量。
Declaration
[Range(0F, 1F)]
[Tooltip("Volume of media player.\n媒體播放器音量。")]
public float volume
Field Value
Type | Description |
---|---|
System.Single |
volumeBar
Image elements to display volume percentage.
Image 元素用於顯示音量百分比。
Declaration
[Tooltip("Image elements to display volume percentage.\nImage 元素用於顯示音量百分比。")]
public List<Image> volumeBar
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.UI.Image> |
volumeControl
Volume control element.
音量控制元素。
Declaration
[Tooltip("Volume control element.\n音量控制元素。")]
public SliderControl volumeControl
Field Value
Type | Description |
---|---|
SliderControl |
volumeText
Text elements to display volume.
Text 元素用於顯示音量。
Declaration
[Tooltip("Text elements to display volume.\nText 元素用於顯示音量。")]
public List<Text> volumeText
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<UnityEngine.UI.Text> |
Properties
currentMedia
Return the current media is loaded.
傳回目前載入的媒體。
Declaration
public Media currentMedia { get; }
Property Value
Type | Description |
---|---|
Media |
Methods
First()
Goto first medium.
跳至第一個媒體。
Declaration
public void First()
First(Single, Single, Boolean)
Goto first medium.
跳至第一個媒體。
First(0, -1)
Declaration
public void First(float start, float end = -1F, bool play = true)
Parameters
Type | Name | Description |
---|---|---|
System.Single | start | Start time |
System.Single | end | End time Default: -1 = Media length 媒體長度 |
System.Boolean | play | Play the media |
Last()
Goto last medium.
跳至最後一個媒體。
Declaration
public void Last()
Last(Single, Single, Boolean)
Goto last medium.
跳至最後一個媒體。
Last(0, -1)
Declaration
public void Last(float start, float end = -1F, bool play = true)
Parameters
Type | Name | Description |
---|---|---|
System.Single | start | Start time |
System.Single | end | End time Default: -1 = Media length 媒體長度 |
System.Boolean | play | Play the media |
LoadAudio(String, Int32, AudioSource, ExternalAudio)
Load audio.
載入音訊。
LoadAudio("C:/abc/def.mp3", 1)
Declaration
public void LoadAudio(string path, int channel = 0, AudioSource audioSource = null, ExternalAudio audio = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path of file |
System.Int32 | channel | Channel of audio type media |
UnityEngine.AudioSource | audioSource | Audio soruce component |
ExternalAudio | audio | External audio setting |
LoadImage(String, Single, ExternalAudio)
Load image.
載入影像。
LoadImage("C:/abc/def.jpg", 3)
Declaration
public void LoadImage(string path, float duration = 3F, ExternalAudio audio = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path of file |
System.Single | duration | Play duration of image type media |
ExternalAudio | audio | External audio setting |
LoadVideo(String, Boolean, ExternalAudio)
Load video.
載入視訊。
LoadVideo("C:/abc/def.mp4", true)
Declaration
public void LoadVideo(string path, bool preview = false, ExternalAudio audio = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path of file |
System.Boolean | preview | Load preview image of video type media if true |
ExternalAudio | audio | External audio setting |
Next()
Goto next medium.
跳至下一個媒體。
Declaration
public void Next()
Next(Int32, Single, Single, Boolean)
Goto next medium.
跳至下個媒體。
Next(1, 0, -1)
Declaration
public void Next(int next, float start = 0F, float end = -1F, bool play = true)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | next | Next to |
System.Single | start | Start time |
System.Single | end | End time Default: -1 = Media length 媒體長度 |
System.Boolean | play | Play the media |
Open(String)
Clear all loaded media and Load all media in the target path.
清除已載入的所有媒體及載入目標路徑中的所有媒體。
Open("../Resources/Media")
Declaration
public void Open(string path)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Directory or File path |
Pause()
Pause the media player.
暫停媒體播放器。
Declaration
public void Pause()
Play()
Play media.
播放媒體。
Declaration
public void Play()
Play(Int32, Int32, Int32, Single, Single)
Play media from start time to end time with external audio.
由開始時間播放媒體及外置音訊至結束時間。
Play(0, 1, 0, 0, -1)
Declaration
public void Play(int index, int auidoChannel, int audioIndex, float start, float end = -1F)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Media index |
System.Int32 | auidoChannel | External audio channel |
System.Int32 | audioIndex | External audio index |
System.Single | start | Start time |
System.Single | end | End time Default: -1 = Media length 媒體長度 |
Play(Int32, Int32, String, Single, Single)
Play media from start time to end time with external audio.
由開始時間播放媒體及外置音訊至結束時間。
Play(0, 1, "def.mp3", 0, -1)
Declaration
public void Play(int index, int auidoChannel, string audioName, float start, float end = -1F)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Media index |
System.Int32 | auidoChannel | External audio channel |
System.String | audioName | External audio index |
System.Single | start | Start time |
System.Single | end | End time Default: -1 = Media length 媒體長度 |
Play(Int32, Single, Single)
Play media from start time to end time.
由開始時間播放媒體至結束時間。
Play(0, 0, -1)
Declaration
public void Play(int index, float start = 0F, float end = -1F)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Media index |
System.Single | start | Start time |
System.Single | end | End time Default: -1 = Media length 媒體長度 |
Play(Single, Single)
Play media from start time to end time.
由開始時間播放媒體至結束時間。
Play(0, -1)
Declaration
public void Play(float start, float end = -1F)
Parameters
Type | Name | Description |
---|---|---|
System.Single | start | Start time |
System.Single | end | End time Default: -1 = Media length 媒體長度 |
Play(String, Int32, Int32, Single, Single)
Play media from start time to end time with external audio.
由開始時間播放媒體及外置音訊至結束時間。
Play("abc.mp4", 1, 0, 0, -1)
Declaration
public void Play(string name, int auidoChannel, int audioIndex, float start, float end = -1F)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Media name |
System.Int32 | auidoChannel | External audio channel |
System.Int32 | audioIndex | External audio index |
System.Single | start | Start time |
System.Single | end | End time Default: -1 = Media length 媒體長度 |
Play(String, Int32, String, Single, Single)
Play media from start time to end time with external audio.
由開始時間播放媒體及外置音訊至結束時間。
Play("abc.mp4", 1, "def.mp3", 0, -1)
Declaration
public void Play(string name, int auidoChannel, string audioName, float start, float end = -1F)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Media name |
System.Int32 | auidoChannel | External audio channel |
System.String | audioName | External audio index |
System.Single | start | Start time |
System.Single | end | End time Default: -1 = Media length 媒體長度 |
Play(String, Single, Single)
Play media from start time to end time.
由開始時間播放媒體至結束時間。
Play("abc.mp4", 0, -1)
Declaration
public void Play(string name, float start = 0F, float end = -1F)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Media name |
System.Single | start | Start time |
System.Single | end | End time Default: -1 = Media length 媒體長度 |
PlayPause()
Play or pause the media player. 播放或暫停媒體播放器。
Declaration
public void PlayPause()
Previous()
Goto previous medium.
跳至上個媒體。
Declaration
public void Previous()
Previous(Int32, Single, Single, Boolean)
Goto previous medium.
跳至上個媒體。
Previous(1, 0, -1)
Declaration
public void Previous(int previous, float start = 0F, float end = -1F, bool play = true)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | previous | Previous to |
System.Single | start | Start time |
System.Single | end | End time Default: -1 = Media length 媒體長度 |
System.Boolean | play | Play the media |
Seek()
Seek the time of media by time control slider.
根據時間控制滑動器尋找媒體時間。
Declaration
public void Seek()
Seek(Boolean)
Seek the time of media by time control slider.
根據時間控制滑動器尋找媒體時間。
Seek()
Declaration
public void Seek(bool play)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | play | Play after seek |
SetAutoNext()
Change auto next setting.
更改自動跳至下一個媒體設定。
Declaration
public void SetAutoNext()
SetAutoNext(Boolean)
Set auto next.
設定是否自動跳至下一個媒體。
SetAutoNext(true)
Declaration
public void SetAutoNext(bool auto)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | auto | Auto next if true |
SetAutoPlay()
Change auto play setting.
更改自動播放設定。
Declaration
public void SetAutoPlay()
SetAutoPlay(Boolean)
Set auto play or not.
設定是否自動播放。
SetAutoPlay(true)
Declaration
public void SetAutoPlay(bool auto)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | auto | Auto play if true |
SetLoop()
Change loop setting.
更改循環設定。
Declaration
public void SetLoop()
SetLoop(Loop)
Set the loop state.
設定循環狀態。
SetLoop(Loop.One)
Declaration
public void SetLoop(Loop loop)
Parameters
Type | Name | Description |
---|---|---|
Loop | loop | Loop setting |
SetMute()
Change mute setting.
更改靜音設定。
Declaration
public void SetMute()
SetMute(Boolean)
Set mute or not.
設定是否靜音。
SetMute(true)
Declaration
public void SetMute(bool mute)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | mute |
SetRandom()
Change random play setting.
更改隨機播放設定。
Declaration
public void SetRandom()
SetRandom(Boolean)
Set random play or not.
設定是否隨機播放。
SetRandom(true)
Declaration
public void SetRandom(bool random)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | random | Random play if true |
SetVolume()
Set the volume of media player by volume control slider.
根據音樂控制滑動器設定媒體擋放器音量。
Declaration
public void SetVolume()
SetVolume(Single)
Set the volume of media player.
設定媒體擋放器音量。
SetVolume(1)
Declaration
public void SetVolume(float volume)
Parameters
Type | Name | Description |
---|---|---|
System.Single | volume | Volume |
SetVolume(Parameter)
Set the volume of media player.
設定媒體擋放器音量。
SetVolume(new Parameter{ single = 1 })
Declaration
public void SetVolume(Parameter parameter)
Parameters
Type | Name | Description |
---|---|---|
Parameter | parameter | Paramter class |
Stop()
Stop the current medium.
停止播放目前媒體。
Declaration
public void Stop()
StopAll()
Stop all channels media.
停止播放所有頻道媒體。
Declaration
public void StopAll()
UnPause()
UnPause the media player.
繼續播放媒體。
Declaration
public void UnPause()