में रीफ्रेश मीडिया स्रोत मैं अपने एंड्रॉइड ऐप में वीडियो चलाने के लिए Exo Player
ExtractorMediaSource
का उपयोग कर रहा हूं। मैं सर्वर से मीडिया डाउनलोड कर रहा हूं और स्थानीय डेटाबेस में और एक विशिष्ट समय पर सहेज रहा हूं अलार्म मैं इस मीडिया को एक्सो प्लेयर में ConcatenatingMediaSource
का उपयोग करके चलाता हूं। लेकिन सबसे पहले मैं जांचता हूं कि डाउनलोड की गई सभी वीडियो फ़ाइल डाउनलोड की गई हैं या नहीं और डाउनलोड मीडिया स्रोत के साथ प्लेयर शुरू करें। और किसी भी वीडियो तो डाउनलोड नहीं किया जाता है, तो मैं जब यह तो डाउनलोड की समय पृष्ठभूमि में डाउनलोड कर सकें मैं अपने पहले से बनाए प्लेलिस्ट में इस वीडियो को जोड़ना चाहते हैंexoplayer
यह नमूना कोड
private void playAndUpdateVideo(ArrayList<String> mediaSourc) {
simpleExoPlayerView.setVisibility(View.VISIBLE);
simpleExoPlayerView.setDefaultArtwork(null);
mainHandler = new Handler();
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
dataSourceFactory = new DefaultDataSourceFactory(context,
Util.getUserAgent(context, "com.cloveritservices.hype"), bandwidthMeter);
// 2. Create a default LoadControl
extractorsFactory = new DefaultExtractorsFactory();
LoadControl loadControl = new DefaultLoadControl();
// 3. Create the player
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
player.addListener(this);
//Set media controller
simpleExoPlayerView.setUseController(false);
simpleExoPlayerView.requestFocus();
// Bind the player to the view.
simpleExoPlayerView.setPlayer(player);
MediaSource[] mediaSources = new MediaSource[mediaSourc.size()];
for (int i=0;i<mediaSourc.size();i++)
{
mediaSources[i]= buildMediaSource(Uri.parse(mediaSourc.get(i)));
}
MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0]
: new ConcatenatingMediaSource(mediaSources);
LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource);
player.prepare(loopingSource);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
boolean isChecked = settings.getBoolean("switch", false);
if (!isChecked)
player.setVolume(0f);
else player.setVolume(2f);
player.setPlayWhenReady(true);
}
और यहाँ है मैं वीडियो फ़ाइल के लिए जाँच कर रहा हूँ कि यह डाउनलोड किया जाता है या नहीं
if (CommonUtils.isExternalStorageExistAndWritable()) {
for (int i = 0; i < videoUrl.size(); i++) {
if (!new File(Environment.getExternalStorageDirectory().toString() + Constants.PROFILE_VIDEO_FOLDER + CommonUtils.fileFromUrl(videoUrl.get(i))).exists() && !CommonUtils.currentlyDownloading(context,CommonUtils.fileFromUrl(videoUrl.get(i)))) {
downloadByDownloadManager(videoUrl.get(i), CommonUtils.fileFromUrl(videoUrl.get(i)));
if (flag==Constants.FLAG_PLAY){downloadFlag=true;}
}
}
} else {
Toast.makeText(getApplicationContext(), "SD Card not mounted.Please Mount SD Card", Toast.LENGTH_SHORT).show();
}
if (flag==Constants.FLAG_PLAY && !downloadFlag)
{
playAndUpdateVideo(videoUrl);
}
public void downloadByDownloadManager(String url, String fileName1) {
downloadUrl=url;
fileName=fileName1;
request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("video file");
request.setTitle(fileName);
request.setNotificationVisibility(2);
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
request.setDestinationInExternalPublicDir(Constants.PROFILE_VIDEO_FOLDER, fileName);
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
// get download service and enqueue file
}
कृपया मदद कि कैसे याद आ रही वीडियो फ़ाइल जोड़ने के लिए बाद में अगर यह डाउनलोड नहीं किया जाता प्लेलिस्ट में।
फ़ाइल डाउनलोड होने के बाद आप इसे प्लेलिस्ट में जोड़ना चाहते हैं? –
हाँ लेकिन न प्लेलिस्ट को फिर से intialize करने के लिए @ SagarPujari –
यू कोड है जिसमें आप फ़ाइल डाउनलोड कर रहे हैं साझा कर सकते हैं चाहता हूँ। –