Android Question VideoView Cannot Play Video message box

RJB

Active Member
Licensed User
Longtime User
"Cannot play video - Sorry, this video cannot be played"

Has anyone ever found/ implemented a way around this error message? i.e. how to stop the message, catch the error or even detect in the code that it has happened?
 

RJB

Active Member
Licensed User
Longtime User
I was wondering if anyone implemented the 'listener library' as mentioned in the "catch Video View error" question?
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Do you want to test the attached library?

AudioExtras
Author:
Martin Pearman
Version: 0.01
  • VideoViewOnErrorListener
    Events:
    • Error (What As Int, Extra As Int) As Boolean
    Fields:
    • MEDIA_ERROR_IO As Int
      A possible value for the 'Extra' parameter.
    • MEDIA_ERROR_MALFORMED As Int
      A possible value for the 'Extra' parameter.
    • MEDIA_ERROR_SERVER_DIES As Int
      A possible value for the 'What' parameter.
    • MEDIA_ERROR_TIMED_OUT As Int
      A possible value for the 'Extra' parameter.
    • MEDIA_ERROR_UNKNOWN As Int
      A possible value for the 'What' parameter.
    • MEDIA_ERROR_UNSUPPORTED As Int
      A possible value for the 'Extra' parameter.
    Methods:
    • ClearOnErrorListener (VideoView1 As VideoViewWrapper)
      Clear any error listener for VideoView1.
    • SetOnErrorListener (VideoView1 As VideoViewWrapper, EventName As String)
      Create and set an error listener for VideoView1.
      The error listener will raise the event:
      Error(What As Int, Extra As Int) As Boolean
      Your callback must return a Boolean value to indicate whether or not it has consumed the event.

I just put it together and it's entirely untested.
Usage looks pretty logical to me so i shan't go into detail.

Martin.
 

Attachments

  • AudioExtras-20140314.zip
    5.2 KB · Views: 860
Upvote 0

RJB

Active Member
Licensed User
Longtime User
Hi Martin,
(I'm in Suffolk, so relatively nearby!)

Thanks for this. It's looking good!
I've used this for testing:

B4X:
Sub Globals
        Dim vv1 As VideoView
        Dim vvl As VideoViewOnErrorListener
End Sub

Sub Activity_Create(FirstTime As Boolean)
        vv1.Initialize("vv")
        vvl.SetOnErrorListener(vv1, "vvl")
        Activity.AddView(vv1, 0dip, 10dip, 250dip, 250dip)
        File.Copy(File.DirAssets, "IMAG0018.mp4", File.DirInternal, "IMAG0018.mp4")
        vv1.LoadVideo(File.DirInternal, "IMAG0018.mp4")
        vv1.Play
End Sub

Sub vvl_error(What As Int, Extra As Int) As Boolean

    Select Case What
        Case vvl.MEDIA_ERROR_SERVER_DIES
            Log("vv error what: SERVER_DIES")
        Case vvl.MEDIA_ERROR_UNKNOWN
            Log("vv error what: ERROR_UNKNOWN")
        Case Else
            Log("vv error what else: " & What)
    End Select
    Select Case Extra
        Case vvl.MEDIA_ERROR_IO
            Log("vv error Extra: IO")
        Case vvl.MEDIA_ERROR_MALFORMED
            Log("vv error Extra:_MALFORMED")
        Case vvl.MEDIA_ERROR_TIMED_OUT
            Log("vv error Extra: TIMED_OUT")
        Case vvl.MEDIA_ERROR_UNSUPPORTED
            Log("vv error Extra: UNSUPPORTED")
        Case Else
            Log("vv error Extra else: " & Extra)
    End Select
   
    Return True        'Message Box suppressed, vv_complete does not execute
'    Return False    'Message Box shows and vv_Complete executes

End Sub

Sub vv_Complete
    Log("Playing complete")
End Sub

Just a couple of queries:

What does the value -2147483648 for 'extra' mean

Could an int be returned instead of a Boolean to give the following actions?
0 = Message Box suppressed, vv_complete does not execute; as existing 'return true'
1 = Message Box suppressed, vv_complete executes; not sure if this would ever be useful
2 = Message Box shows and vv_Complete does not execute; use to avoid endless loops
3 = Message Box shows and vv_Complete executes as existing 'return false'

Thanks again
Robin
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
The MediaPlayer constants are all listed on this page: http://developer.android.com/reference/android/media/MediaPlayer.html#MEDIA_ERROR_TIMED_OUT.

I see no value for -2147483648.
Google tells me that -2147483648 is hex -0x80000000 and again i see no constant value that matches.
Have a look through the error code constant values and see if you can make sense of it.

I'd have thought that the constant values documented on this page are the only constant values passed in the event - but you're seeing other values are you?

The MediaPlayer.OnErrorListener returns only a boolean value to the MediaPlayer to indicate whether the application has handled the error or not.
There's no way to return any value other than boolean True or False.

Martin.
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
The MediaPlayer constants are all listed on this page: http://developer.android.com/reference/android/media/MediaPlayer.html#MEDIA_ERROR_TIMED_OUT.

I see no value for -2147483648.
Google tells me that -2147483648 is hex -0x80000000 and again i see no constant value that matches.
Have a look through the error code constant values and see if you can make sense of it.

I'd have thought that the constant values documented on this page are the only constant values passed in the event - but you're seeing other values are you?

The MediaPlayer.OnErrorListener returns only a boolean value to the MediaPlayer to indicate whether the application has handled the error or not.
There's no way to return any value other than boolean True or False.

Martin.

Thank. It's a shame about the Boolean value but obviously nothing can be done.

Yes I'm seeing the value mentioned: I'll take a look at the documentation but when the videoview can't play the video the 'what' value returns MEDIA_ERROR_UNKNOWN and the 'extra' value returns -2147483648 !
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
The theory will be that the 'extra' value will always be one of:
  • MEDIA_ERROR_IO
  • MEDIA_ERROR_MALFORMED
  • MEDIA_ERROR_TIMED_OUT
  • MEDIA_ERROR_UNSUPPORTED

In practice it may be that older versions of android returned other values for the 'extra' value and/or that newer versions of android will return other values.
Or it just might be that the documentation isn't as good as it could be...

Martin.
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Martin,
you have so many GOODIES distributed in various threads all over the forum. Hopefully one day you will find some time to add (most of ) them to the WIKI-list. ;)
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hmmm there's nothing in the library source that should have been effected by the latest b4a update.

B4X:
@Author("Martin Pearman")
@Events(values={
	"Error(What As Int, Extra As Int) As Boolean"
})
@ShortName("VideoViewOnErrorListener")
@Version(0.01f)
public class VideoViewOnErrorListener{

	/**
	 * A possible value for the 'What' parameter.
	 */
	public static final int MEDIA_ERROR_UNKNOWN=MediaPlayer.MEDIA_ERROR_UNKNOWN;
	

	/**
	 * A possible value for the 'What' parameter.
	 */
	public static final int 	MEDIA_ERROR_SERVER_DIES=MediaPlayer.MEDIA_ERROR_SERVER_DIED;
	
	/**
	 * A possible value for the 'Extra' parameter.
	 */
	public static final int MEDIA_ERROR_IO=MediaPlayer.MEDIA_ERROR_IO;

	/**
	 * A possible value for the 'Extra' parameter.
	 */
	public static final int MEDIA_ERROR_MALFORMED=MediaPlayer.MEDIA_ERROR_MALFORMED;

	/**
	 * A possible value for the 'Extra' parameter.
	 */
	public static final int MEDIA_ERROR_UNSUPPORTED=MediaPlayer.MEDIA_ERROR_UNSUPPORTED;

	/**
	 * A possible value for the 'Extra' parameter.
	 */
	public static final int MEDIA_ERROR_TIMED_OUT=MediaPlayer.MEDIA_ERROR_TIMED_OUT;
	
	/**
	 * Clear any error listener for VideoView1.
	 */
	public static void ClearOnErrorListener(VideoViewWrapper VideoView1){
		VideoView1.getObject().setOnErrorListener(null);
	}
	
	/**
	 * Create and set an error listener for VideoView1.
	 * The error listener will raise the event:
	 * Error(What As Int, Extra As Int) As Boolean
	 * Your callback must return a Boolean value to indicate whether or not it has consumed the event.
	 */
	public static void SetOnErrorListener(final VideoViewWrapper VideoView1, final BA pBA, String EventName){
		final String onErrorEventName=(EventName+"_Error").toLowerCase(BA.cul);
		if(pBA.subExists(onErrorEventName)){
			VideoView1.getObject().setOnErrorListener(new android.media.MediaPlayer.OnErrorListener(){
				@Override
				public boolean onError(MediaPlayer pMediaPlayer, int pWhat, int pExtra) {
					boolean consumeEvent=false;
					Object object=pBA.raiseEvent(VideoView1, onErrorEventName, new Object[]{pWhat, pExtra});
					if(object instanceof Boolean){
						consumeEvent=((Boolean) object).booleanValue();
					}
					return consumeEvent;
				}
			});
		} else {
			BA.LogError("MediaPlayerOnErrorListener not initialized, callback sub not found: "+EventName+"_Error");
		}
	}
}

Can you check the log and make sure that you don't see the "MediaPlayerOnErrorListener not initialized, callback sub not found" message?

Martin.
 
Upvote 0

jazzzzzzz

Active Member
Licensed User
Longtime User
No logs are showing about media error...Can you please check whether you have this problem ?
That is first compile by 3.5 then compile by 3.8?
 
Upvote 0
Top