首页 > 解决方案 > Mp4 file from Url is taking too long to play

问题描述

I have a mp4 Url, which is containing 400mb of video. Using exoplayer, it's taking too long (10-15 min) for start the playing the video. I have added loadcontrol but no use. Can anybody help me ?

  MediaSource videoSource = new 
  ExtractorMediaSource.Factory(dataSourceFactory)
            .createMediaSource(mUri);
    // Prepare the player with the source.
    Log.d("exo","to be prepare");
    player.prepare(videoSource);
    Log.d("exo","prepared"+videoSource);

    player.setPlayWhenReady(true);
    Log.d("exo","played");

    player.addListener(this);

============================

LoadControl loadControl = new DefaultLoadControl( new DefaultAllocator(true, 16), VideoPlayerConfig.MIN_BUFFER_DURATION, VideoPlayerConfig.MAX_BUFFER_DURATION, VideoPlayerConfig.MIN_PLAYBACK_START_BUFFER, VideoPlayerConfig.MIN_PLAYBACK_RESUME_BUFFER, -1, true);

        BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
        TrackSelection.Factory videoTrackSelectionFactory =
                new AdaptiveTrackSelection.Factory(bandwidthMeter);
        TrackSelector trackSelector =
                new DefaultTrackSelector(videoTrackSelectionFactory);
        // 2. Create the player
        player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), trackSelector, loadControl);
        videoFullScreenPlayer.setPlayer(player);

标签: javaandroid

解决方案


This might have multiple causes:

1. The max buffer duration is too large

Try to play with setting a lower value for VideoPlayerConfig.MAX_BUFFER_DURATION (which is 30 seconds apparently)

2. Your streaming video protocol is not efficient

It possibly has to do with the video encoding in combination with your network speed limitations. I'm guessing that the video player is loading the entire video, or at least a massive chunk of it) before it plays. That's why Protocols like "HTTP Live Stream" solve this problem and lead to videos playing nearly instantly, as the protocol sends chunks of videos, and adjusts the bandwidth dynamically.

3. Your internet connection is relatively slow

While this is probably not the main cause, it might affect the outcome.


推荐阅读