Android Exoplayer play UDP streaming no audio

1.4k views Asked by At

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..

2

There are 2 answers

0
Bineesh Kumar On

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);
    }
2
Ankit Lathiya On

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);
}