package com.offline.music.playermp3.media3;

import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSource;
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory;


public class testSourceFactory implements  DataSource.Factory {
//    private final CacheDataSource.Factory cacheDataSourceFactory;
//    private final ExoPlayer player;
    private DefaultMediaSourceFactory mediaSourceFactory;

//    public DynamicMediaSourceFactory(DefaultMediaSourceFactory factory,CacheDataSource.Factory cacheDataSourceFactory, ExoPlayer exoPlayer) {
//        this.cacheDataSourceFactory = cacheDataSourceFactory;
//        this.player = exoPlayer;
//        this.mediaSourceFactory = factory;
//    }
    public testSourceFactory(DefaultMediaSourceFactory factory) {

        this.mediaSourceFactory = factory;
    }



    @UnstableApi
    @Override
    public DataSource createDataSource() {




//        RetrofitManager.getInstance().getPlayUrl(mediaItem.mediaId, new RequestListener<ResponseBody>() {
//
//            @Override
//            public void onFail(String errorMsg) {
//
//            }
//
//            @Override
//            public void onSuccess(ResponseBody data) {
//                JSONObject jsonObject = CommonUtils.toJsonObject(data);
//                if (jsonObject != null) {
//                    ResponsePlayUrl responsePlayUrl = JsonHelper.ResolvePlayUrlJson(jsonObject);
//                    if (responsePlayUrl == null) {
//                        // TODO: 2024/9/27
//                        return;
//                    }
//                    String uri = "";
//                    if (responsePlayUrl.getAudioUrlMedium() != null) {
//                        uri = responsePlayUrl.getAudioUrlMedium();
//                    } else {
//                        uri = responsePlayUrl.getAudioUrlLow();
//                    }
//                    CommonUtils.LogMsg("------createMediaSource----------="+mediaItem.mediaId+"---------"+uri);
//                    ProgressiveMediaSource mediaSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
//                            .createMediaSource(MediaItem.fromUri(uri));
//                    player.setMediaSource(mediaSource);
//                    player.prepare();
//
//                }
//
//
//            }
//        });
        return null;
    }
}
