Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question Is there a way for Exoplayer to prepare Source faster #5513

Closed
mathemandy opened this issue Feb 14, 2019 · 5 comments
Closed

Question Is there a way for Exoplayer to prepare Source faster #5513

mathemandy opened this issue Feb 14, 2019 · 5 comments
Assignees

Comments

@mathemandy
Copy link

Hi, is there away i can prepare my source Faster?
lets say i get all 100 songs from the server , from the console i see exoplayer taking forever to prepare source as it logs this on the Console.

2019-02-14 12:47:45.938 12735-12947/ng.groove.udux W/zygote: Long monitor contention with owner DefaultHlsPlaylistTracker:MasterPlaylist (12951) at void com.google.android.exoplayer2.upstream.cache.SimpleCache.applyContentMetadataMutations(java.lang.String, com.google.android.exoplayer2.upstream.cache.ContentMetadataMutations)(SimpleCache.java:-1) waiters=0 in void com.google.android.exoplayer2.upstream.cache.SimpleCache.applyContentMetadataMutations(java.lang.String, com.google.android.exoplayer2.upstream.cache.ContentMetadataMutations) for 408ms

This is how i prepare my source

void prepareSource(Track track, ShuffleOrder order) {
        try {
            if (order != null) {
                mediaSource.setShuffleOrder(order);
            }
        } catch (Exception e) {

        }
        HlsMediaSource addedMediaSource = new
                HlsMediaSource(Uri.parse(track.getSource()), cacheDataSourceFactory(),
                2, null, null);

        if (mediaSource == null) {
            mediaSource = new ConcatenatingMediaSource();
        }
        mediaSource.addMediaSource(addedMediaSource);
    }

This is my cacheDataSourceFactory() method

    private DataSource.Factory cacheDataSourceFactory() {
        return () -> {
            byte[] secret = getUtf8Bytes("ng.groove.udux_1");
            AesCipherDataSource aesCipherDataSource = new AesCipherDataSource(secret, new FileDataSource());
            byte[] scratch = new byte[3897];

            AesCipherDataSink aesCipherDataSink = new AesCipherDataSink(secret, new CacheDataSink(UduxCache.getInstance(), Long.MAX_VALUE), scratch);

            CacheDataSource cd = new CacheDataSource(UduxCache.getInstance(), okHttpDataSourceFactory().createDataSource(), aesCipherDataSource, aesCipherDataSink,
                    CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR, null);
            cd.addTransferListener(mTransferListener);
            return cd;
        };
    }

Here is the cache instance

  public static synchronized  SimpleCache getInstance() {
        if (sDownloadCache == null)
        downloadContentDirectory = new File(getDownloadDirectory(), DOWNLOAD_CONTENT_DIRECTORY);
        if ( !SimpleCache.isCacheFolderLocked(downloadContentDirectory)){
            return sDownloadCache = new SimpleCache(downloadContentDirectory,new NoOpCacheEvictor());
        }else {

            return  sDownloadCache;

        }
    }




    private static File getDownloadDirectory() {
        if (downloadDirectory == null) {
            downloadDirectory = ApplicationContext.get().getExternalFilesDir(null);
            if (downloadDirectory == null) {
                downloadDirectory = ApplicationContext.get().getFilesDir();
            }
        }
        return downloadDirectory;
    }


Is there anyway i can improve this and reduce loading time before playing song.
Thanks

@erdemguven
Copy link
Contributor

Which version of ExoPlayer are you using? If it isn't the development branch, could you try and let us know if it fixes the issue.

@mathemandy
Copy link
Author

I am using Exo Version
implementation 'com.google.android.exoplayer:exoplayer:2.9.4'

@erdemguven erdemguven assigned ojw28 and unassigned erdemguven Feb 15, 2019
@ojw28
Copy link
Contributor

ojw28 commented Feb 18, 2019

I think you're seeing poor cache performance. Improving this is tracked by #4253. Closing as duplicate.

@ojw28 ojw28 closed this as completed Feb 18, 2019
@mathemandy
Copy link
Author

@ojw28 #4323 i looked at the issue and did not understand if i am to wait for an update to the proposed solution or try to solve that myself using the recommended discussion.
Thanks

@ojw28
Copy link
Contributor

ojw28 commented Feb 18, 2019

It's probably easier for you to wait until the issue is marked as fixed in this case, and then migrate to the first version of ExoPlayer that picks up the improvements (likely 2.10.0).

@google google locked and limited conversation to collaborators Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants