Android videoView gives me Alert "Sorry,This video cannot be played"? - android

My Code::
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri
.parse("www.logisticinfotech.com/client/Malasiya Cup/movie.mp4");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
Error::Sorry,This video cannot be played.
Logcat::
01-03 20:19:14.044: DEBUG/AndroidRuntime(454): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
01-03 20:19:14.044: DEBUG/AndroidRuntime(454): CheckJNI is ON
01-03 20:19:14.224: DEBUG/AndroidRuntime(454): --- registering native functions ---
01-03 20:19:14.874: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.logistic.videoview/.MainActivity }
01-03 20:19:15.014: DEBUG/AndroidRuntime(454): Shutting down VM
01-03 20:19:15.044: DEBUG/dalvikvm(454): Debugger has detached; object registry had 1 entries
01-03 20:19:15.134: INFO/AndroidRuntime(454): NOTE: attach of thread 'Binder Thread #3' failed
01-03 20:19:15.784: INFO/StagefrightPlayer(34): setDataSource('www.logisticinfotech.com/client/Malasiya Cup/movie.mp4')
01-03 20:19:15.805: ERROR/MediaPlayer(420): error (1, -2147483648)
01-03 20:19:15.834: INFO/ActivityManager(59): Displayed activity com.logistic.videoview/.MainActivity: 821 ms (total 821 ms)
01-03 20:19:15.885: ERROR/MediaPlayer(420): Error (1,-2147483648)
01-03 20:19:15.885: DEBUG/VideoView(420): Error: 1,-2147483648

I'd recommend you have a look at Android's overview of supported media formats. This site covers everything from the first versions of Android to the latest:
Android Supported Media Formats
I'm guessing you're trying to include a video in your application, and that it needs to work on all devices, so I'd suggest you go ahead and try to encode a video with a profile similar to the SD (High quality) listed on the above mentioned site.
There are plenty of free video converters available that you can use for encoding the video - one of them could be Freemake Video Converter.

To expand further on my comment, I had fought a lot with different encodings/formats/etc until I got the one that worked on all android devices (at least all that I tested). Using ffmpeg, here's what finally worked:
/usr/bin/ffmpeg -i inputfile.ext -y -s 320x240 -vcodec libx264 -vpre medium -vpre baseline -acodec libfaac output.mp4

I have the same problem , I just figured out that it cames from the video format and encoding. But I didn't really fing the combination thet works on all devices.
thanks for give the answer if you find it!

i had d same issue
and i resolved by adding a delay of 250ms. actually the error occurs when we try to capture and play immediately. At that time, the engine is not yet ready to play (coz it hasnt reached End of streami.e. hasnt read the video completely)

Related

android:mediaplayer error(1, -12)

When I call getCurrentMillis in android media player it throws IllegalStateException and I see the following in the logs:
E/MediaPlayer: error (1, -12)
I have checked that the video is being correctly prepared.
It also causes OnErrorListener.onError to be called with args 1 and -12.
In the end I found that this was caused by trying to play a video which was only 48px wide. Since I had cropped the video in ffmpeg from a larger one I was able to use a bigger crop. When I increased the width to 64px, the error no longer occurred.
Maybe media player has an undocumented minimum allowed size or maybe the narrower crop was in violation of the H264 spec or something. Hope this helps someone.

MediaPlayer sometimes not preparing when screen is locked

I have a MusicService for MediaPlayback, wich uses a MediaPlayer with the settings:
player.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
and those Listeners are set:
OnPreparedListener, OnCompletionListener, OnErrorListener, OnSeekCompleteListener
The MediaPlayer is used for mp3-Playback. When one Song is finished, onCompletion is called. Then PlayNext is called, wich resets the MediaPlayer, then sets the Datasource with the URI of the next Track. Uri is loaded with:
Uri trackUri = ContentUris
.withAppendedId(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, songId);
Then the Player is prepared, then the player is started. This is working fine, but only sometimes, when the Device is locked and played about 1-3 Songs while it was locked and the next Song should start, the Player doesn't prepare until i hit the power button. Figured out, that if I don't hit the PowerButton it takes the Player about 2 Minutes to prepare.
I've Logged everything now and made a few custom outputs with Log.e(...).
This is put out before prepare() (prepareAsync() delivers the same result) is called:
E/MusicService: Preparing now...
This is put out, when onPrepared is called:
E/MusicService: Player prepared.
So this is the full Device-Output after "Preparing now..." is put out:
04-02 13:54:55.506 12517-12517/at.htlleonding.musync E/MusicService: Preparing now.
04-02 13:54:55.525 811-888/? E/libsuspend: Error writing to /sys/power/state: Device or resource busy
04-02 13:54:55.544 246-14756/? D/offload_visualizer: thread exit
04-02 13:54:55.546 246-14754/? V/offload_effect_bundle: offload_effects_bundle_hal_stop_output output 1879 pcm_id 9
04-02 13:54:55.546 246-14754/? D/hardware_info: hw_info_append_hw_type : device_name = speaker
04-02 13:54:55.549 246-14752/? E/audio_hw_primary: offload_thread_loop: Compress handle is NULL
04-02 13:54:55.549 246-924/? D/audio_hw_primary: adev_close_output_stream: enter:stream_handle(0xb5bfa640)
04-02 13:54:55.549 246-924/? D/audio_hw_primary: out_standby: enter: stream (0xb5bfa640) usecase(3: compress-offload-playback)
04-02 13:54:55.555 246-924/? W/AudioFlinger: moveEffectChain_l() effect chain for session 0 not on source thread 0xb59fa000
04-02 13:54:55.611 246-15030/? I/FFmpegExtractor: android-source:0xb1834060
04-02 13:54:55.820 811-888/? E/libsuspend: Error writing to /sys/power/state: Device or resource busy
04-02 13:54:55.972 246-15030/? I/FFMPEG: [mp3 # 0xae2f4400] Skipping 0 bytes of junk at 2177007.
... Then theres no output until i hit the PowerButton. Then the Song is prepared.
If someone is interested in the full output after I hit the PowerButton until "Player prepared" is called, I created a Gist here.
Sidenote:
While the App is used, a few Album-Covers are displayed in some Fragments. They are loaded with Picasso, so I don't need to worry about memory caching. Some ImageViews are filled without Picasso (for example the ImageViews that hold the drawables of my PlayerControls). Maybe there are Problems with the memory/resources?
I might have found the answer in another thread where some faced the same problem while streaming music here.
My final solution is to use a WakeLock, wich I require before preparing a Song and release again onPrepared and onError and onDestroy of my Service. It's important to release it again to save Battery. Make sure to check if the WakeLock is held before releasing it.
I create my WakeLock like this in onCreate of my Service:
PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MusicService");
aquire:
wakeLock.acquire();
release:
if(wakeLock.isHeld())
wakeLock.release();
Tested the Playback now for about 10 Minutes and didn't stop until now. I don't know if this is a very battery-saving solution

vlc http stream with android

I compiled vlc for android with version 1.8 and I found a official demo with link:
https://bitbucket.org/edwardcw/libvlc-android-sample .It's works fine with localVideo. I try to play a http stream, so I change the code below:
// Create LibVLC
// TODO: make this more robust, and sync with audio demo
ArrayList<String> options = new ArrayList<String>();
//options.add("--subsdec-encoding <encoding>");
options.add("--aout=opensles");
options.add("--audio-time-stretch"); // time stretching
options.add("-vvv"); // verbosity
libvlc = new LibVLC(options);
libvlc.setOnHardwareAccelerationError(this);
holder.setKeepScreenOn(true);
// Create media player
mMediaPlayer = new MediaPlayer(libvlc);
mMediaPlayer.setEventListener(mPlayerListener);
// Set up video output
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.setVideoView(mSurface);
//vout.setSubtitlesView(mSurfaceSubtitles);
vout.addCallback(this);
vout.attachViews();
//Media m = new Media(libvlc, media);
Uri uri = Uri.parse(httpAddress);
Media m = new Media(libvlc, uri);
mMediaPlayer.setMedia(m);
mMediaPlayer.play();
It's works fine on samsung,android 4.1.2. But it's crash with mi4 mobile. with start, it's has 2 seconds sound without image, then it's crash,just like ANR but stay the black screen for ever.
here is the logcat:
core video output: picture is too late to be displayed (missing 953 ms)
core vout display: Failed to change zoom
android_window vout display: change source crop/aspect
core video output: picture is too late to be displayed (missing 1156 ms)
core vout display: auto hiding mouse cursor
core audio output: playback too late (66254): up-sampling
core video output: picture is too late to be displayed (missing 1155 ms)
core video output: picture is too late to be displayed (missing 1153 ms)
[OMX.qcom.video.decoder.avc] ERROR(0x80001009)
Codec reported an error. (omx error 0x80001009, internalError -2147483648)
mediacodec decoder: Exception in MediaCodec.dequeueOutputBuffer
mediacodec decoder: dequeue_out failed
mediacodec decoder: OutThread stopped
threadid=16: thread exiting, not yet detached (count=0)
Error with hardware acceleration
more log info
where can i find a httpstream demo with vlc complied 1.8?
Thanks for your help
Issue of this nature are due to HardwareDecoder on board, this awesome page compiles up all the Decoding capability on Android.
The MediaCodec class first became available in Android 4.1 (API 16).
In Android 4.3 (API 18), MediaCodec was expanded to include a way to provide input through a Surface (via the createInputSurface method).
Even though Android Introduced MediaCodec in a big way on 4.3, not all vendors support them, need to have intelligent Player/Decoder to switch to Software Decoding.
LibVLC does it intelligently but need to manage it through LibVLC Options.

"RingtoneManager: unable to find a usable ringtone" persistent error

Some users of our app are reporting that ringtones fail to load as expected. I've included a typical logcat output from one of these users below. It seems that the request for the default ringtone is returning null ("Failed to open ringtone content://settings/system/ringtone"). I've asked these users to change ringtones, and sometimes this resolves the issue, but in other cases (HTC Hero in both the ones I know of) changing the ringtone does not fix the problem. I have been unable to reproduce this problem on any of our test devices. Any thoughts as to what might cause this, how to debug, or how to resolve?
D/Ringtone( 743): create mAudio
D/MediaPlayer( 743): setDataSource(44, 0, 576460752303423487) pid = 743
E/Mp3HwPlayer( 56): ID:24, new Mp3HwPlayer
E/MediaPlayerService( 56): getPlayerType(): Has ID3 info, size = 1024
E/MediaPlayerService( 56): getPlayerType(): Input buffer is MPA format
E/Mp3HwPlayer( 56): ID:24, destory Mp3HwPlayer
D/MediaPlayerService( 56): Create Player playertype=6
D/MediaPlayerService( 56): new PVPlayer for MP3
D/PVPlayer( 56): setDataSource(25, 0, 180143)
D/MediaPlayerService( 56): MediaPlayerService::Client::setDataSource exit
D/MediaPlayerService( 56): returned from setDataSource() in MediaPlayerService::create
D/MediaPlayerService( 56): [23] prepareAsync
I/PlayerDriver( 56): OpenCore disable firewall payload
W/MediaPlayer( 743): info/warning (1, 26)
E/PlayerDriver( 56): Command PLAYER_PREPARE completed with an error or info PVMFErrResource
E/MediaPlayer( 743): error (1, -17)
E/RingtoneManager( 743): Failed to open ringtone content://settings/system/ringtone
E/RingtoneManager( 743): unable to find a usable ringtone
E/IncomingRinger( 743): Couldn't find a ringtone for URI: content://settings/system/ringtone
It looks like the ringtone is stored on a SD card, and you haven't permission to read SD data, so it returns null. I got similar problem with my mediaPlayer.

Android Shoutcast: Want help to play ShoutCast Streaming in 1.6

My application plays ShoutCast Streaming and the target OS is 1.6 and above. I have applied some code from NPR application with some modification.
Here is the code
mediaPlayer = new MediaPlayer();
mediaPlayer.reset();
mediaPlayer.setDataSource(url);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
// Log.d(LOG_TAG, "Preparing: " + playUrl);
mediaPlayer.prepareAsync();
mediaPlayer.start();`
The code doesnot play anything on simulator or device(Testing in Samsung Galaxy with 2.1).
Here is the LogCat message.
About to play http://88.191.81.31:8206
12-08 14:16:42.229: WARN/MediaPlayer(5520): info/warning (1, 26)
12-08 14:16:42.239: ERROR/PlayerDriver(1870): Command PLAYER_INIT completed with an error or info PVMFFailure
12-08 14:16:42.239: ERROR/MediaPlayer(5520): error (1, -1)
12-08 14:16:42.239: WARN/PlayerDriver(1870): PVMFInfoErrorHandlingComplete
12-08 14:16:42.259: ERROR/MediaPlayer(5520): start called in state 0
12-08 14:16:42.259: ERROR/MediaPlayer(5520): error (-38, 0)
12-08 14:16:42.299: INFO/MediaPlayer(5520): Info (1,26)
12-08 14:16:42.299: ERROR/MediaPlayer(5520): Error (1,-1)
12-08 14:16:42.304: ERROR/MediaPlayer(5520): Error (-38,0)
Here is the question. 1. Can you tell me whats happening in device? 2. How to solve this error?.
You are calling start() too soon. Javadocs of MediaPlayer explain it (look at the picture):
Either you have to call prepare() before you call start(), or
You call prepareAsync() and wait for OnPreparedListener.onPrepared() to be called, then (possibly inside this method) call start().
Updated:
Shoutcast streams are nativelly supported only on 2.2. For earlier versions you must create local proxy that changes the response protocol from ICY (shoutcast) to HTTP, which the
mediaplayer will support. Take a look at this:
http://code.google.com/p/npr-android-app/source/browse/trunk/Npr/src/org/npr/android/news/StreamProxy.java
This has previously been discussed:
Listen to a shoutcast with Android

Categories

Resources