se-bastiaan / TorrentStream-Android

A torrent streamer library for Android based on libtorrent4j
Other
343 stars 108 forks source link

Playing the torrent while its being downloaded #26

Closed 4gus71n closed 7 years ago

4gus71n commented 7 years ago

Hi there!

I've been using your library in the development of a music torrent download App. I'm trying to figure out a way of playing the music files while they are being downloaded, but I'm stuck with that. I wrote a question in stackoverflow about it. I was wondering if you ever tried to do something like this. And if you did, ¿how did you achieve that?

Regards,

vonclutch commented 7 years ago

hey, You need to use a streaming mediaplayer lib like VLC or exoplayer. Not all mediplayer has a correct implementation for streaming. Take a look to exomedia, it's a wrapper for exoplayer, the new mediaplayer from Google. It's rly light unlike VLC (30/40mb) and works pretty well.

And by the way, you should implement a service for the download part to avoid conflict.

4gus71n commented 7 years ago

Thanks! Using the ExoMedia library solved the issue, here's the snippet that I used:

compile 'com.devbrackets.android:exomedia:3.1.0'

final EMAudioPlayer mediaPlayer = new EMAudioPlayer (getApplicationContext());
            mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
                @Override
                public void onPrepared() {
                    mediaPlayer.start();
                }
            });
            mediaPlayer.setDataSource(getApplicationContext(), Uri.parse(mCurrentTrack));
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mediaPlayer.prepareAsync();
se-bastiaan commented 7 years ago

I actually never tried playing music using this library, but I understand that it does work? Maybe I should change the library a bit to make it more convenient for both video and audio usage 🤔

ExoMedia is indeed a perfect way of using ExoPlayer and a great alternative to VLC, since they still do not have an easy way of using it as a library. Another alternative that you could that a look at is ijkplayer.

vonclutch commented 7 years ago

I don't think it's rly usefull to make change for the music, it's not rly the purpose of this lib to take care of what you're doing with your media you download. The mediplayer should take care of that, it's not the job of a lib-torrent :)