Beispiel #1
0
        void _OnPlaybackCompleted(MPMP instance)
        {
            mpmpMaster.SeekTo(0f);
            _mpmpClients.ForEach(c => { if (c != null)
                                        {
                                            c.SeekTo(0f);
                                        }
                                 });

            mpmpMaster.Play();
            _mpmpClients.ForEach(c => { if (c != null)
                                        {
                                            c.Play();
                                        }
                                 });
        }
Beispiel #2
0
        private string savePath;                                                                      // = Application.persistentDataPath + "/Data"; C:/MPMP_CACHE


        IEnumerator Start()
        {
            Debug.Log("MPMP_APITest.START");
            if (mediaPlayer == null)
            {
                Debug.Log("MPMP_APITest could not run. You have to specify the mediaPlayer!");
                yield break;
            }

            mediaPlayer.OnLoad              += _OnLoad;
            mediaPlayer.OnLoaded            += _OnLoaded;
            mediaPlayer.OnPause             += _OnPause;
            mediaPlayer.OnPlay              += _OnPlay;
            mediaPlayer.OnDestroyed         += _OnDestroyed;
            mediaPlayer.OnPlaybackCompleted += _OnPlaybackCompleted;
            mediaPlayer.OnError             += _OnError;
            mediaPlayer.OnBuffering         += _OnBuffering;



            mediaPlayer.autoPlay = false;
            mediaPlayer.looping  = false;
            mediaPlayer.volume   = 0.1f;
            //On mobile platforms a little delay prevents loading issues!
            yield return(new WaitForSeconds(2f));

            mediaPlayer.Load(loadPathLocal);

            while (mediaPlayer.IsLoading())
            {
                yield return(new WaitForSeconds(0.5f));
            }

            Debug.Log("MPMP_APITest.Loading.READY");

            mediaPlayer.Play();

            yield return(new WaitForSeconds(5f));

            mediaPlayer.Pause();

            yield return(new WaitForSeconds(2f));

            mediaPlayer.SeekTo(0f);

            yield return(new WaitForSeconds(1f));

            mediaPlayer.SeekTo(10f);//seeking to sec

            yield return(new WaitForSeconds(1f));

            mediaPlayer.SeekTo(0.5f, true);//normalized seeking

            yield return(new WaitForSeconds(1f));

            mediaPlayer.Play();

            // yield break;

            yield return(new WaitForSeconds(1f));

            if (String.IsNullOrEmpty(savePath))
            {
                savePath = Application.persistentDataPath + "/Data";
            }

            Debug.Log("savePath:" + savePath);

            Uri  loadUri = new Uri(loadPath);
            Uri  saveUri = new Uri(Path.Combine(savePath, Path.GetFileName(loadUri.AbsoluteUri)).Replace(@"\", "/"));
            bool saved   = true;

            Debug.Log("saveUri: " + saveUri.AbsolutePath);

            if (!System.IO.File.Exists(saveUri.AbsolutePath))
            {
                saved = false;
                yield return(StartCoroutine(mediaPlayer.DownloadAndSaveData(loadUri, saveUri, (flag) => { saved = flag; }, (progressAmount) => { Debug.Log(String.Format("{0} percent downloaded", progressAmount)); })));
            }

            if (!saved)
            {
                Debug.LogWarning("Error loading or saving data");
                yield break;
            }

            Debug.Log("new video is available");

            // yield break;

            if (videoTransform.GetComponent <MeshRenderer>() != null)
            {
                videoTransform.GetComponent <MeshRenderer>().material = newVideoMaterial;
            }


            mediaPlayer.SetVideoMaterial(newVideoMaterial);

            mediaPlayer.autoPlay = true;
            mediaPlayer.looping  = false;

            mediaPlayer.Load(saveUri.AbsoluteUri);


            Debug.Log("videoPath:" + mediaPlayer.videoPath);
            yield return(new WaitForSeconds(5));

            if (Application.platform.ToString().StartsWith("Windows"))
            {
                mediaPlayer.filtermode = MPMP.FilterModeMPMP.Point;
                yield return(new WaitForSeconds(5));

                mediaPlayer.filtermode = MPMP.FilterModeMPMP.Bilinear;
            }
            //Destroy(mediaPlayer.gameObject);
            yield break;
        }
Beispiel #3
0
        override public void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();
            //DrawDefaultInspector();//debug

            serializedObject.Update();



            GUILayout.BeginVertical("box");

            GUILayout.BeginHorizontal(); //1.

            GUILayout.BeginHorizontal(); //2
            Rect rect = GUILayoutUtility.GetRect(tex_logo.width, tex_logo.height);

            GUI.DrawTexture(rect, tex_logo);
            //GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();//2

            GUILayout.Space(0);

            GUILayout.BeginVertical();//3

            //Toggles
            GUILayout.BeginHorizontal();
            // GUILayout.FlexibleSpace();
            EditorGUIUtility.labelWidth = 60f;
            EditorGUILayout.PropertyField(autoPlayProp, new GUIContent("AutoPlay", "Video starts immediately after loading."));
            _target.autoPlay = autoPlayProp.boolValue;
            // GUILayout.FlexibleSpace();
            GUILayout.Space(10);
            EditorGUILayout.PropertyField(loopingProp, new GUIContent("Looping", "Video loops endless."));
            _target.looping = loopingProp.boolValue;

            GUILayout.Space(10);
            EditorGUIUtility.labelWidth = 100f;
            EditorGUILayout.PropertyField(forceGammaProp, new GUIContent("Force Gamma", "NVIDIA has trouble on Windows 10 with linear colorspace. This option enforces that always a rgb instead of a srgb native texture is used. But you need a gamma correction shader for the right display of your videotexture."));
            //_target.forceGamma  = forceGammaProp.boolValue;



            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.Space(5);

            //Buttons
            GUILayout.BeginHorizontal();
            // GUILayout.FlexibleSpace();
            GUI.backgroundColor = _target.IsLoading() ? _loadColor : Color.white;
            if (GUILayout.Button("Load", GUILayout.Height(30f), GUILayout.Width(60f)))
            {
                _target.Load();
            }

            GUI.backgroundColor = _target.IsPlaying() ? _playColor : Color.white;
            if (GUILayout.Button("Play", GUILayout.Height(30f), GUILayout.Width(60f)))
            {
                _target.Play();
            }

            GUI.backgroundColor = _target.IsPaused() ? _pauseColor : Color.white;
            if (GUILayout.Button("Pause", GUILayout.Height(30f), GUILayout.Width(60f)))
            {
                _target.Pause();
            }

            GUI.backgroundColor = _target.IsStopped() ? _stopColor : Color.white;
            if (GUILayout.Button("Stop", GUILayout.Height(30f), GUILayout.Width(60f)))
            {
                _target.Stop();
            }

            GUI.backgroundColor = Color.white;

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();   //3

            GUILayout.EndHorizontal(); //1.

            GUILayout.Space(5);

            //Sliders
            GUILayout.BeginHorizontal();
            EditorGUIUtility.labelWidth = 50f;
            //can't work with serialized properties here, because we want to call into the native plugin
            EditorGUILayout.LabelField(new GUIContent("Seek", "Normalized values 0 -1 "), GUILayout.Width(46f));
            // _target.seek = EditorGUILayout.Slider(_target.seek, 0.0f, 1.0f, GUILayout.MinWidth(100f), GUILayout.MaxWidth(300f));
            _target.SeekTo(EditorGUILayout.Slider(_target.GetSeek(true), 0.0f, 1.0f, GUILayout.MinWidth(100f), GUILayout.MaxWidth(300f)), true);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            //EditorGUIUtility.fieldWidth = 50f;
            EditorGUIUtility.labelWidth = 50f;
            EditorGUILayout.Slider(volumeProp, 0.0f, 1.0f, new GUIContent("Volume", "Normalized values 0 -1"), GUILayout.MinWidth(100f), GUILayout.MaxWidth(350f));
            _target.volume = volumeProp.floatValue;

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            //EditorGUIUtility.fieldWidth = 50f;
            EditorGUIUtility.labelWidth = 50f;
            EditorGUILayout.Slider(balanceProp, -1.0f, 1.0f, new GUIContent("Balance", "Adjust the stereo channel volume output. \n-1 = only left channel \n0 = both channels equal \n1 = only right channel"), GUILayout.MinWidth(100f), GUILayout.MaxWidth(350f));
            _target.balance = balanceProp.floatValue;

            GUILayout.EndHorizontal();

            GUILayout.Space(10);

            EditorGUIUtility.labelWidth = 85f;
            EditorGUILayout.PropertyField(videoPathProp, new GUIContent("videoPath", "Path to a video file. Depending on the sheme the path is resolved in a different way:\n\nNo sheme: streamingAssets folder is the root.\nfile:// : Absolute path from a valid volume.\nhttp:// : the video is loaded from the url. Your video should be a stream or a progressiv streaming video file "));

            GUILayout.Space(10);

            GUI.enabled = (!Application.isPlaying);

            EditorGUILayout.PropertyField(videoMaterialProp, new GUIContent("videoMaterial", "The Material(shader with '_MainTex' property) that should receive the video texture."));


            GUILayout.Space(10);

            GUILayout.BeginVertical("box");

            EditorGUIUtility.labelWidth = 85f;
            bool isTexturePropertyNotDefault = texturePropertyNameProp.stringValue != MPMP.DEFAULT_TEXTURE_NAME;

            GUI.backgroundColor = isTexturePropertyNotDefault ? MPMP.WARNING_COLOR: Color.white;//GUI.contentColor
            EditorGUILayout.PropertyField(texturePropertyNameProp, new GUIContent("Texture Name", "Name of the texture property within the materials shader, default is _MainTex.\nChange this only if you use some custom shader."));
            GUI.backgroundColor = Color.white;
            if (String.IsNullOrEmpty(texturePropertyNameProp.stringValue))
            {
                string msg = String.Format("If you leave this property empty the default name '{0}' will be used!", MPMP.DEFAULT_TEXTURE_NAME);
                EditorGUILayout.HelpBox(msg, MessageType.Warning, true);
            }



            if (_isOnWindows)
            {
                GUILayout.Space(5);
                EditorGUILayout.PropertyField(filtermodeProp, new GUIContent("Filter mode", "Texture filterMode option is only supported under Windows. Use Bilinear for better quality."));
            }

            GUI.enabled = true;

            GUILayout.EndVertical();//box


            serializedObject.ApplyModifiedProperties();
            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(_target);
            }


            GUILayout.Space(5);
            EditorGUIUtility.labelWidth = 150f;

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.Slider(updateFrequencyProp, 1.0f, 120.0f, new GUIContent("Update frequency", "Set the frequency how often per second the native plugin should update.\nKeep in mind that the real maximal frequency depends on the framerate of your app."), GUILayout.MinWidth(100f), GUILayout.MaxWidth(350f));

            serializedObject.ApplyModifiedProperties();
            if (EditorGUI.EndChangeCheck())
            {
                _target.SetUpdateFrequency(updateFrequencyProp.floatValue);
                EditorUtility.SetDirty(_target);
            }


            GUILayout.Space(5);
            EditorGUIUtility.labelWidth = 150f;

            EditorGUI.BeginChangeCheck();
            // EditorGUILayout.Slider(updateFrequencyProp, 1.0f, 120.0f, new GUIContent("Update frequency", "Set the frequency how often per second the native plugin should update.\nKeep in mind that the real maximal frequency depends on the framerate of your app."), GUILayout.MinWidth(100f), GUILayout.MaxWidth(350f));
            EditorGUILayout.PropertyField(preventFlickerProp, new GUIContent("Prevent flicker", "If this option is enabled a copy of the current video frame is made when start loading to prevent flicker. This operation could impact your performance and cause a short delay."));
            _target.preventFlicker = preventFlickerProp.boolValue;
            // serializedObject.ApplyModifiedProperties();
            if (EditorGUI.EndChangeCheck())
            {
                //_target.SetUpdateFrequency(updateFrequencyProp.floatValue);
                EditorUtility.SetDirty(_target);
            }



            GUILayout.EndVertical();



            EditorGUI.BeginChangeCheck();

            foldoutPreviewProp.boolValue = EditorGUILayout.Foldout(foldoutPreviewProp.boolValue, "Preview Video");
            if (foldoutPreviewProp.boolValue)
            {
                tex_preview = _target.GetVideoTexture();
                if (tex_preview != null)
                {
                    //Vector2 videoSize = _target.GetNativeVideoSize();
                    float w  = EditorGUIUtility.currentViewWidth;
                    float wx = w / tex_preview.width;// videoSize.x;// tex_preview.width;
                    //Debug.Log(w);
                    //Debug.Log(tex_preview.width);

                    Rect rect2 = GUILayoutUtility.GetRect(w, Mathf.Floor(tex_preview.height * wx));
                    Rect rect3 = new Rect(rect2.x, rect2.y + rect2.height, rect2.width, -rect2.height);

                    //  Rect rect2 = GUILayoutUtility.GetRect(w, Mathf.Floor(videoSize.y * wx));
                    //  Rect rect3 = new Rect(rect2.x, rect2.y + rect2.height, rect2.width, -rect2.height);

                    GUI.DrawTexture(rect3, tex_preview);//,ScaleMode.ScaleToFit
                }

                EditorUtility.SetDirty(_target);//Force redraw
            }



            serializedObject.ApplyModifiedProperties();
            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(_target);
            }
        }