I'm working with the media player on a streaming application (RTSP):
Video and sound are played great but when an incoming call pauses the Activity, the Surface is destroyed (I know this because of traces in SurfaceHolder.Callback).
Once the call finishes, the activity is resumed and a new Surface is created. I've tried to assign it to the player via setDisplay(SurfaceHolder sh) method but so far, only the sound of the video can be heard.
The work around to resume a video stream is:
Restart the MediaPlayer object.
Wait for the buffer to fill.
Perform a seek via the mediaPlayer.
Wait for the buffer to fill.
This is annoying as the player should be able to be paused when a call is received, bind the new surface when the call completed and the Activity resume and play the video with no buffering at all.
Have you tried overriding "onStop" or even "onDestroy" and somehow make the player persitent?
Edith just showed me the timestamp of this question. Is it of any interest still?
Related
I am having a problem (I think) with overlapping threads playing music in my android mp3 player. I have a class SongList.java that lists and plays music when an item is clicked and a ArtistList.java that intents SongList to play songs by that specific artist. Two or more songs will play at the same time if they are not in the same activity.
How do I tell my playSong method to stop all threads but the most recent one?
You should have just one single Thread or service doing playback.
SongList and ArtistList should not start a new service. Rather you should have a PlaybackService you can pass a SongList or ArtistList as parameter / argument. If doing so, you should just have one single Thread doing playback and never run into that kind of trouble.
Have a look here:
http://developer.android.com/guide/topics/media/mediaplayer.html#mpandservices
They implement a Service that uses the build in MediaPlayer for audio playback. Next you can bind your MusicPlaybackService to an activity.
Here is an introduction:
http://developer.android.com/guide/components/bound-services.html
You can specify methods that the activity can invoke on your service with the help of Binder. So you could provide a method like playSongs(SongList songs) or playArtists(ArtistList list) that could be invoked by the activity (i.e. by clicking on a certain button). Since the service runs the playback (by using MediaPlayer) the service is responsible for Threading and playback. So if you call playSongs(SongList songs) of the service, the Service should stop MediaPlayer and restart MediaPlayer with the desired music file (provided by SongList). With this approach your MusicPlaybackService manages the playback and guarantees that only one music file is played simultaneously.
Im working on a Music Player app, and all the music handled by the app are from streaming resources.
Everytime the user changes songs, i need to call reset and set a new dataSource. If the user rapidly switches songs, and the MediaPlayer is on the preparing state, the UI from my app freezes.
This only happens if i call reset and the media player is in the preparing state.
How can i prevent my app UI from freezing and getting an ANR?
PS: Im using prepareAsync(), not prepare().
See setOnPreparedListener. You can keep track of the state in your class through various listeners and avoid calling prepareAsync().
You might have better luck also calling stop() before reset().
http://developer.android.com/reference/android/media/MediaPlayer.html#setOnPreparedListener%28android.media.MediaPlayer.OnPreparedListener%29
I'm currently developing a custom camera application which takes a video using MediaRecorder for 5 seconds. I have implemented a number countdown overlay which counts down from 5.
My problem is that I am not 100% sure how to implement surface methods and pause/resume methods. If I close my app half way through recording and then open it again, the app freezes, shows a black screen, and eventually crashes.
Should onPause and surfaceDestroyed be used in unison? (Same question applies to onResume and surfaceCreated) How does surfaceChanged fit into this?
I'm guessing I need to find a way to restart my CameraActivity every time it resumes. (As I don't want it resuming half way through a countdown).
You should look at Activity lifecycle onPause and onResume for creating and destroying camera.
http://developer.android.com/training/basics/activity-lifecycle/pausing.html#Pause
How to pause a video in vlcj?
I am using web camera. So i use the dshow in vlcj on windows.
Code is:
String[] options = {
":dshow-adev=none",
":dshow-vdev=",
":dshow-aspect-ratio=4:3",
":sout-mov-faststart",
":dshow-size=640x480",
":sout=#duplicate{dst=display,
dst='tran
scode{vcodec=h264,venc=x264,vb=1000,
fps=1,scale=1,width=640,height=480}:
standard{access=file,,mux=mov,dst="+fileName+"}'}"
};
mediaPlayer.prepareMedia("dshow://",options);
If i use default pause, that time the video is paused
Ex: mediaPlayer.pause();. But the video is stored in cache. So I click the play button then the video played with the delayed time.
What i need is if i pause the video the video should pause recording and after press the play it should resume the recording. Similar to JMF.
Can any one please provide the answer?
You can use two instances of media player; such that the first instance just receives input and forwards it to a special UDP port. The output should be available at a url such as: udp://#127.0.0.1:20001. Then you can start the main media player using the output of first player as input. After that you can play or stop the first player to start or stop stream. Because UDP is connection-less the second player will work fine.
I am using the default Android Media Player in an Activity, trying to play back a couple of video files. However I have a problem with programming what I want. The desired program outcome would be the following:
A video file is played back
After that, a dialog is shown, asking the user something
A pause of 5 seconds occurs
The next video is shown
and so forth
How am I to program this? Currently, I use a paradigm like the following:
I have a method that sets up the player for theĀ a file, e.g. playVideo(int) So I pass it the first file.
When the player is prepared, it will be started in onPrepared(MediaPlayer).
When the video is finished, the onCompletion(MediaPlayer) listener of the media player shows the dialog to the user by calling showDialog().
The user accepts the dialog. Before calling dismiss() on the dialog, the player object is started for the next file by calling playVideo(int).
This works, but it feels a bit quirky and not clean. And it's of course very procedural. The problems are:
that I can't figure out how to insert a pause after the dialog is dismissed.
that I maybe want to change the presentation order of dialogs and videos and this ain't too easy now
Has anyone got an idea?
For the pause, you could use the AlarmManager to schedule an alarm five seconds from now. It will launch an intent, and that intent could call playVideo(int).