2

im new in android webview, i play video in android webview using exoplayer, there are 2 category video that i play, first mp4, working well. second streaming (unicast m3u8 and UDP) the video play well but no audio, i try play in stream vlc the source has audio,

this is my code.

private void initializePlayerMulticast(Uri mUri) {
        Toast.makeText(ExoPlayer.this, "Hello bro multicast woi hehee", Toast.LENGTH_LONG).show();

        player = ExoPlayerFactory.newSimpleInstance(this);
        UdpDataSource.Factory test = buildDataSourceFactory();
        ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
        ExtractorMediaSource mediaSource = new ExtractorMediaSource
                .Factory(test)
                .setExtractorsFactory(extractorsFactory)
                .createMediaSource(mUri);
        videoView.setPlayer(player);
        player.prepare(mediaSource);
        player.setPlayWhenReady(true);
    }

    private DataSource.Factory buildDataSourceFactory() {
        return new UdpDataSource.Factory() {
            @Override
            public DataSource createDataSource() {
                return new UdpDataSource(5000, 100000);
            }
        };
    }

sory for bad english..

Jimbo
  • 49
  • 8

2 Answers2

0

You can use below code to play .m3u8 file:-

Handler mHandler = new Handler();

String userAgent = Util.getUserAgent(context, "APP_NAME");

DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(
                userAgent, null,
                DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                1800000,
                true);

HlsMediaSource mediaSource = new HlsMediaSource(Uri.parse(mediaUrl),dataSourceFactory, 1800000,mHandler, null);

if (mediaUrl != null) {
    videoPlayer.prepare(mediaSource);
    videoPlayer.setPlayWhenReady(true);
}
Ankit Lathiya
  • 199
  • 1
  • 12
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – stasiaks Mar 17 '20 at 06:54
  • thank you for your answer @AnkitLathiya but, i found the solution when i install ffmpeg and connect it with exoplayer.. using my code above its working.. – Jimbo Apr 29 '20 at 01:58
0

In my case also audio was an issue. So I fixed it by ensuring bitrate is higher than 20 ( it can be 1 also ) and along with that height of video. The code is as below :

private void extractYoutubeUrl() {
        new YouTubeExtractor(this) {
            @SuppressLint("StaticFieldLeak")
            @Override
            public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta vMeta) {

                if (ytFiles != null) {
                    for (int i = 0, itag; i < ytFiles.size(); i++) {
                        itag = ytFiles.keyAt(i);
                        YtFile ytFile = ytFiles.get(itag);                       
                        String extn=ytFile.getFormat().getExt();
                        int height = ytFile.getFormat().getHeight();
                        int audibit = ytFile.getFormat().getAudioBitrate();
                        if(height>200 & audibit>20){
                            playVideo(ytFile.getUrl());
                            Log.i("audiobitrate",String.valueOf(ytFile.getFormat().getAudioBitrate()));
                        }
                    }

                }else{
                    
                }
            }
        }
        .extract(mYoutubeLink, true, true);
    }
Bineesh Kumar
  • 123
  • 10