Example #1
0
    /// <summary>
    /// Loads the movie.
    ///
    /// In case it fails, exception is thrown
    /// </summary>
    protected virtual void Load(MovieSource source, LoadOptions loadOptions = null)
    {
        // use temporary vars when loading and then assign them to instance vars.
        // this way if the loading fails, the MoviePlayer is still in consistent state.
        AudioClip tmpAudioBuffer;
        Texture2D tmpFramebuffer;

        // Actually try to load the movie.
        // In case of failure, exception is thrown here and the currently playing movie keeps playing
        var loadedMovie = MoviePlayerUtil.Load(source, out tmpFramebuffer, out tmpAudioBuffer, loadOptions);

        // new movie loaded successfully. if there was a movie previously loaded, unload it
        if (movie != null)
        {
            MoviePlayerUtil.Unload(movie);
        }

        movie = loadedMovie;

        // reset stats
        _framesDropped = 0;
        _syncEvents    = 0;

        // make the loaded movie visible and hearable
        framebuffer = tmpFramebuffer;
        if (tmpAudioBuffer != null)
        {
            audiobuffer = tmpAudioBuffer;
        }
        Bind();
    }
Example #2
0
    void ExtractOneFrame()
    {
                #if UNITY_WEBPLAYER || UNITY_WEBGL
        Debug.Log("This example doesn't work in web player");
                #else
        // First we load the movie, but not using a MoviePlayer component, but a
        // MoviePlayerUtil class. The Load method requires a System.IO.Stream as an input
        // and returns a framebuffer Texture2D and AudioClip which is optional.
        // The Load method detects the stream type, initializes a Demux that can read audio and
        // video streams in it and then it creates stream Decoder instances that you will use
        // to extract video frames or audio samples.
        Texture2D framebuffer;
        Movie     movie = MoviePlayerUtil.Load(File.OpenRead(infile), out framebuffer);
        if (movie.demux.hasVideo)
        {
            // Invoking a Decoder like this will fetch an encoded frame bytes from Demux
            // and decode it into framebuffer texture specified earlier. There is
            // another overload that doesn't take a frame as an argument, but returns it
            // instead. This is used with Streamer demux where you have sequential access only.
            movie.videoDecoder.Decode(frame);
        }

        // Just encode the frame as PNG and write to disk
        File.WriteAllBytes(frameOutFile, framebuffer.EncodeToPNG());
        Debug.Log("Extracted frame " + frame);
                #endif
    }
Example #3
0
 void ExtractRawAudio()
 {
             #if UNITY_WEBPLAYER || UNITY_WEBGL
     Debug.Log("This example doesn't work in web player");
             #else
     // ExtractRawVideo is thread safe. Multiple instances of it can run on the same System.IO.Stream
     RunInBackgroundOrNot(delegate() {
         File.WriteAllBytes(outfile, MoviePlayerUtil.ExtractRawAudio(File.OpenRead(infile)));
     });
             #endif
 }
Example #4
0
    public void Unload()
    {
        if (movie != null)
        {
            // stop the audio
            if (GetComponent <AudioSource>() != null)
            {
                GetComponent <AudioSource>().Stop();
            }

            // unload all other resources associated with the movie
            MoviePlayerUtil.Unload(movie);
            movie = null;
        }
    }