Currently I am on an assignment where we have to create a mediaplayer.
I am using the JavaFX MediaPlayer, but it does not have a way of changing the media, without creating the object as a new MediaPlayer everytime you want change media.
I have been looking around for a library of some sort, which have this support, but I have not yet been able to find one.
My question is if this is even a possibility, if such a thing exist, or if the correct way would be to just create the new MediaPlayer every time I want to switch media?
Related
I'm new to android app development and just creating a simple application for my workplace that allows video playback control from a web panel, so the app pings the panel on a loop and if it gets a request to play a video, it plays it. If it gets a request to stop the video or play something else, then it does that.
From MainActivity I'm using startActivity to start an instance of ExoPlayer, I know how to pass variables to the activity, but how do I send information the other way or control the playback? Basically that loop that runs constantly to check for new actions is running in MainActivity, once the player is started I have no ability to stop playback, get stream metrics or do anything with that instance at all. I realise I'm probably doing things backwards and should have a background service do the checks, but I still have no idea how to pass information back and forth.
Does anyone have any tips or suggestions? Thank you!
Instead of using two activities, you have to use an acitivty (the main) and a fragment (the video player). Then define a callback interface which will implement the activity and thus manage the communication between fragment and activity
See this https://blog.mindorks.com/how-to-communicate-between-fragments/
I'm kind of new to android java so I started to create a Music Player app just to learn and practice. The main thing was to control the same MediaPlayer from 2 different activities (In MainActivity there's a listview with the music files and PlayerActivity has the MediaPlayer). I tried to use public voids like:
PlayerActivity pa = new PlayerActivity();
//button onClick
pa.songPlay();
and it kind of worked at first but then a lot of errors occurred when using contexts and MediaPlayer.create(), so I started to look for another way to do this but found none so far. Is there a way to make 2 different layouts with a shared element, and with the same class?
For a better explanation:
MainActivity:
PlayerActivity:
And fuse them like:
Okay so I'm answering my own question because I didn't know that FrameLayouts exist, but since I found them I can put two different layouts into the same space and just set the visibility to VISIBLE or GONE whenever I want to switch between them
I am using ExoPlayer to play my streams. I have implemented Picture in Picture which works pretty good but i haven't been able to implement play, pause controls on PiP window until now. I know that by defaul Exoplayer + Picture in Picture does not give us the Picture in Picture media controls we see in the Youtube player for instance.
Anyway i searched a lot about this issue, and found out a code that may help me but the problem is that the code is in Kotlin and i am using Java, as a beginner i wasn't able to find the alternative code for Java to make it work.
This is the recommendation i got:
val mediaSession = MediaSessionCompat(this, packageName)
val mediaSessionConnector = MediaSessionConnector(mediaSession)
mediaSessionConnector.setPlayer(player, null)
mediaSession.isActive = true
I know that i should implement it onStart() after handling Exoplayer. I thinked about converting my project in Kotlin but as a beginner i would like to focus in Java and instead find a way to fix this.
Android will show media controls in Picture-in-picture mode automatically if there is an active media session for the app.
https://developer.android.com/guide/topics/ui/picture-in-picture
Also, the code you posted belongs to the media session extension library for exoplayer, so you need to add it to your build.gradle
https://github.com/google/ExoPlayer/tree/release-v2/extensions/mediasession
I've figured out that the MediaPlayer on Android 4.4.2 seems to fade-in the Audiofile automatically.
I am using the MediaPlayer for playing a Sound that mustn't be faded in.
It worked well with a Smarthpone with 4.2.1, but on another Phone with 4.4.2 the Fading occurs.
I've also had a look at the SoundPool, but it misses the Feature of letting me know if the File is still playing.
Am I able to switch off the automatic fade-in or do I need to use the Soundpool and keep an eye on the length of the Track on my own?
Thanks,
VanDahken
You can try to setAudioAttributes(AudioAttributes attributes) before start playing.
atrs = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build();
Try to play with CONTENT_TYPE.
I have the same issue. The good thing is that it worked on a couple other Android versions, so hopefully only 4.4.2 has the problem. My first solution I discovered was to use an uncompressed music file... (.wav with data format LEI16) but the music file was way too big.
I also found that the fade-in doesn't seem to happen if you set the audio stream type to STREAM_RING but that's probably not a good idea since it's meant for phone rings.
For my app I only have one critical spot (when the app first starts) where the music has to play without the fade-in, and I was able to get a fix for that. The intro takes a few seconds before the music starts, so what I am doing is:
-prepareAsync() at the start of the intro
-then when prepared, setVolume() to 0f and start()
-then, after a small delay (for my case that ends up being a few seconds: the time it takes for the app's intro to complete), add a seek listener, and seekTo(0)
-when the seek completes, set the volume to the desired value
I am developing application similar to Music Player.
I am using Mediaplayer in android.
I am unable get those effects please help me on this ....
Actually I want to create an equalizer from which I can change the reverb & tone values of music, which MediaPlayer is playing.But I am not getting any way to do it.
Platform : Android
Waiting for response.....
It can be done in 2 ways
One before creating the media player instance you can attach them by creating spepcifc set of profiles
- http://developer.android.com/reference/android/media/MediaPlayer.html#attachAuxEffect(int)
After creating mediaplayer, you can still create new aux and you need give mediaplayer's id with it. You need to set session id for mediaplayer before doing setsource. - setAudioSessionId
Krishna