Ejemplo n.º 1
0
        /// <summary>
        /// Loads movie with audio. It will be ready for playback
        /// </summary>
        /// <param name="source">Source</param>
        /// <param name="targetFramebuffer">Target framebuffer</param>
        /// <param name="targetAudioBuffer">Target audio buffer</param>
        /// <param name="loadOptions">Load options</param>
        public static Movie Load(MovieSource source, out Texture2D targetFramebuffer, out AudioClip targetAudioBuffer, LoadOptions loadOptions = null)
        {
            if (loadOptions == null)
            {
                loadOptions = LoadOptions.Default;
            }

            if (source.stream == null && source.url == null)
            {
                throw new MpException("Either source.stream or source.url must be provided");
            }

            targetFramebuffer = null;
            targetAudioBuffer = null;

            var movie = new Movie();

            movie.sourceStream = source.stream;             // can be NULL

            // create and initialize demux for the source data
            if (source.url != null)
            {
                movie.demux = loadOptions.demuxOverride != null ? loadOptions.demuxOverride : Streamer.forUrl(source.url);
                ((Streamer)movie.demux).Connect(source.url, loadOptions);
            }
            else
            {
                movie.demux = loadOptions.demuxOverride != null ? loadOptions.demuxOverride : Demux.forSource(source.stream);
                movie.demux.Init(source.stream, loadOptions);
            }

            if (movie.demux.hasVideo && !loadOptions.skipVideo)
            {
                var vsi = movie.demux.videoStreamInfo;
                movie.videoDecoder = VideoDecoder.CreateFor(vsi);
                movie.videoDecoder.Init(out targetFramebuffer, movie.demux, loadOptions);

                if (loadOptions.preloadVideo)
                {
                    movie.frameUV = UnpackFramesToAtlas(movie.videoDecoder, ref targetFramebuffer, vsi.frameCount);
                }
                else
                {
                    movie.frameUV = new Rect[1] {
                        new Rect(0, 0, 1, 1)
                    };
                }
            }
            if (movie.demux.hasAudio && !loadOptions.skipAudio)
            {
                movie.audioDecoder = AudioDecoder.CreateFor(movie.demux.audioStreamInfo);
                movie.audioDecoder.Init(out targetAudioBuffer, movie.demux, loadOptions);
            }
            return(movie);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads movie with audio. It will be ready for playback
        /// </summary>
        /// <param name="source">Source</param>
        /// <param name="targetFramebuffer">Target framebuffer</param>
        /// <param name="targetAudioBuffer">Target audio buffer</param>
        /// <param name="loadOptions">Load options</param>
        public static Movie Load(MovieSource source, out Texture2D targetFramebuffer, out AudioClip targetAudioBuffer, LoadOptions loadOptions = null)
        {
            if (loadOptions == null)
                loadOptions = LoadOptions.Default;

            if (source.stream == null && source.url == null) {
                throw new MpException ("Either source.stream or source.url must be provided");
            }

            targetFramebuffer = null;
            targetAudioBuffer = null;

            var movie = new Movie ();
            movie.sourceStream = source.stream; // can be NULL

            // create and initialize demux for the source data
            if (source.url != null) {
                movie.demux = loadOptions.demuxOverride != null ? loadOptions.demuxOverride : Streamer.forUrl (source.url);
                ((Streamer)movie.demux).Connect (source.url, loadOptions);
            } else {
                movie.demux = loadOptions.demuxOverride != null ? loadOptions.demuxOverride : Demux.forSource (source.stream);
                movie.demux.Init (source.stream, loadOptions);
            }

            if (movie.demux.hasVideo && !loadOptions.skipVideo) {
                var vsi = movie.demux.videoStreamInfo;
                movie.videoDecoder = VideoDecoder.CreateFor (vsi);
                movie.videoDecoder.Init (out targetFramebuffer, movie.demux, loadOptions);

                if(loadOptions.preloadVideo) {
                    movie.frameUV = UnpackFramesToAtlas(movie.videoDecoder, ref targetFramebuffer, vsi.frameCount);
                } else {
                    movie.frameUV = new Rect[1] { new Rect(0, 0, 1, 1) };
                }
            }
            if (movie.demux.hasAudio && !loadOptions.skipAudio) {
                movie.audioDecoder = AudioDecoder.CreateFor (movie.demux.audioStreamInfo);
                movie.audioDecoder.Init (out targetAudioBuffer, movie.demux, loadOptions);
            }
            return movie;
        }
Ejemplo n.º 3
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 ();
    }
Ejemplo n.º 4
0
    protected override void Load(MovieSource source, LoadOptions loadOptions = null)
    {
        if (loadOptions == null) {
            loadOptions = this.loadOptions;
        } else {
            this.loadOptions = loadOptions;
        }

        // if we have audioSource set here to override audio in the source stream
        // don't load the audio in the demux.
        bool overrideAudio = audioSource != null && !loadOptions.skipAudio;
        if (overrideAudio)
            loadOptions.skipAudio = true;

        if (overrideAudio)
            audiobuffer = audioSource;

        base.Load (source, loadOptions);

        if (!loadOptions.preloadVideo) {
            if (movie.videoDecoder != null) {
                movie.videoDecoder.Decode (videoFrame);
            }
        }
        UpdateRendererUVRect ();
    }