VideoView setVideoUri No Content Provider - java

I am developing an Android app that needs to play an .mp4 video from my local server.
I have this code:
mPreview = (VideoView) findViewById(R.id.video_preview);
mPreview.setVisibility(View.VISIBLE);
mPreview.setVideoURI(Uri.parse("http://192.168.1.100:7676/getVideoByFileName.php?name=C%3A%2FSpinShot%2FResults%2FSpinShot-201701311359177714.mp4"));
mPreview.setOnPreparedListener(createOnPreparedListener());
private MediaPlayer.OnPreparedListener createOnPreparedListener() {
return new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
};
}
And every time it gets executed, I get this error:
D/MediaPlayer: setDataSource IOException | SecurityException happend :
java.io.FileNotFoundException: No content provider: http://192.168.1.100:7676/getVideoByFileName.php?name=C%3A%2FSpinShot%2FResults%2FSpinShot-201701311359177714.mp4
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1141)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:991)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:914)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1121)
at android.widget.VideoView.openVideo(VideoView.java:371)
at android.widget.VideoView.access$2100(VideoView.java:71)
at android.widget.VideoView$7.surfaceCreated(VideoView.java:652)
at android.view.SurfaceView.updateWindow(SurfaceView.java:712)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:209)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1014)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2510)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1437)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7403)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
at android.view.Choreographer.doCallbacks(Choreographer.java:695)
at android.view.Choreographer.doFrame(Choreographer.java:631)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
No video plays in the VideoView. Any help would be appreciated.

Turns out my Firewall affects their connection. Turned it off and it works just fine.

Related

impossible to start the onStartJob method

I have the following code:
MainActivity.java
package com.example.bluejob;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.util.Log;
import android.view.View;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void scheduleJob(View v) {
ComponentName componentName = new ComponentName(this, BlueJobM.class);
JobInfo info = new JobInfo.Builder(821, componentName)
.setRequiresCharging(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
.setPersisted(true)
.setPeriodic(15 * 60 * 1000)
.build();
JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
int resultCode;
resultCode = scheduler.schedule(info);
if (resultCode == JobScheduler.RESULT_SUCCESS) {
Log.d(TAG, "Job scheduled");
} else {
Log.d(TAG, "Job scheduling failed");
}
}
public void cancelJob(View v) {
JobScheduler scheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
scheduler.cancel(821);
Log.d(TAG, "Job cancelled");
}
}
OnStartJob method in BlueJobM.java
#Override
public boolean onStartJob(JobParameters params) {
Log.d(TAG, "Job started");
doBackgroundWork(params);
return true;
}
When I start the code on my Redmi I revive di series of errors:
2021-09-22 15:33:56.527 21306-21306/com.example.bluejob E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bluejob, PID: 21306
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6608)
at android.view.View.performClickInternal(View.java:6585)
at android.view.View.access$3100(View.java:785)
at android.view.View$PerformClick.run(View.java:25921)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6608) 
at android.view.View.performClickInternal(View.java:6585) 
at android.view.View.access$3100(View.java:785) 
at android.view.View$PerformClick.run(View.java:25921) 
at android.os.Handler.handleCallback(Handler.java:873) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:201) 
at android.app.ActivityThread.main(ActivityThread.java:6810) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
Caused by: java.lang.IllegalArgumentException: No such service ComponentInfo{com.example.bluejob/com.example.bluejob.BlueJobM}
at android.os.Parcel.createException(Parcel.java:1957)
at android.os.Parcel.readException(Parcel.java:1921)
at android.os.Parcel.readException(Parcel.java:1871)
at android.app.job.IJobScheduler$Stub$Proxy.schedule(IJobScheduler.java:184)
at android.app.JobSchedulerImpl.schedule(JobSchedulerImpl.java:44)
"I THINK THE ERROR IS HERE" at com.example.bluejob.MainActivity.scheduleJob(MainActivity.java:32)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385) 
at android.view.View.performClick(View.java:6608) 
at android.view.View.performClickInternal(View.java:6585) 
at android.view.View.access$3100(View.java:785) 
at android.view.View$PerformClick.run(View.java:25921) 
at android.os.Handler.handleCallback(Handler.java:873) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:201) 
at android.app.ActivityThread.main(ActivityThread.java:6810) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.job.JobSchedulerService$JobSchedulerStub.enforceValidJobRequest(JobSchedulerService.java:2538)
at com.android.server.job.JobSchedulerService$JobSchedulerStub.schedule(JobSchedulerService.java:2600)
at android.app.job.IJobScheduler$Stub.onTransact(IJobScheduler.java:60)
at android.os.Binder.execTransact(Binder.java:735)
When I start the App I can enter in the CancelJob method which correctly calls onStopJob on BlueJobM.java (i can see the log).
When I remove this part of code form MainActivity.java
int resultCode;
resultCode = scheduler.schedule(info);
if (resultCode == JobScheduler.RESULT_SUCCESS) {
Log.d(TAG, "Job scheduled");
} else {
Log.d(TAG, "Job scheduling failed");
}
the error does not show up but the job doesn't start anyway.
I suspect the program has some problem building the Job but I'm not sure.
I put more code on Github if is needed https://github.com/jaxis/BlueJob.
I was following this tutorial soo the code should be similar to this one https://www.youtube.com/watch?v=3EQWmME-hNA&t .
Thanks in advance.
java.lang.IllegalArgumentException: No such service
ComponentInfo{com.example.bluejob/com.example.bluejob.BlueJobM}
That means it doesn't know anything about that class as a component. Generally this means you didn't add it to the manifest. Every Service and Activity you want to use needs to be in the manifest. In some cases BroadcastReceivers do as well (although not all).

java.lang.UnsatisfiedLinkError: org.bytedeco.javacpp.avutil in start FFmpegFrameGrabber

i have creating slowmotion video app in android and i can try to set video motion speed in any start and ending postion in total video length.
but some error occur in start FFmpegFrameGrabber.
here my code:
private class PrepareMedia extends AsyncTask<Void, Void, Void> {
private PrepareMedia() {
}
protected Void doInBackground(Void... params) {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(viewSource);
try {
grabber.start();
grabber.stop();
grabber.release();
} catch (Exception e) {
Log.e(TAG, "doInBackground: ");
}
return null;
}
}
view my error.
01-12 15:59:16.374 14990-14990/com.example.slowmotiondemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.slowmotiondemo, PID: 14990
java.lang.UnsatisfiedLinkError: org.bytedeco.javacpp.avutil
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:324)
at org.bytedeco.javacpp.Loader.load(Loader.java:585)
at org.bytedeco.javacpp.Loader.load(Loader.java:530)
at org.bytedeco.javacpp.avformat$AVFormatContext.<clinit>(avformat.java:2819)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:468)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:462)
at com.example.slowmotiondemo.ActivityCutMergeVideo.prepareMediaForOreantation(ActivityCutMergeVideo.java:687)
at com.example.slowmotiondemo.ActivityCutMergeVideo.onCreate(ActivityCutMergeVideo.java:507)
at android.app.Activity.performCreate(Activity.java:6904)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7331)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
please tell me how to solve error.
Firstly try manual installation of the javacv (https://github.com/bytedeco/javacv#manual-installation).
Then try to extract .so files from jar and put them into app/src/main/jniLibs.
If that also will not work, then use this manual:
https://github.com/bytedeco/javacpp-presets/wiki/The-UnsatisfiedLinkError-X-File-%28a-real-experience%29

java.lang.IllegalStateException: Could not execute method for android:onClick in android

I am fairly new to Android and creating my first app. I am using using following code:
public class MainActivity extends AppCompatActivity {
int netScore = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void addOne(View view) {
netScore = netScore + 1;
displayScore(netScore);
}
private void displayScore(int printScore) {
TextView varScore = (TextView) findViewById(R.id.score);
varScore.setText(printScore);
}
}
When I click the button, it throws this error in debug:
FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5198) 
at android.view.View$PerformClick.run(View.java:21147) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method)
Does anybody have an idea about this error?
Did try adding the onClick in the xml-layout like this?
android:onClick="method"
If so, make sure that there are no typos.
In your case it would probably be:
android:onClick="addOne"
You can also listen for the click events programmatically. Check out this.
You can set the TextView in OnCreate method:
TextView varScore = (TextView) findViewById(R.id.score);
after that add the ClickListener to the varScore:
enter code here
varScope.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// do anything whatever you want
}
});
At first, try to initiate the TextView in the onCreate method.
BTW could you please show us your .xml file?

java.lang.IllegalStateException MediaPlayer

In my application I use a VideoView where playing a MediaPlayer, and in some cases has released me this error:
java.lang.IllegalStateException
at android.media.MediaPlayer.prepareAsync(Native Method)
at android.widget.VideoView.openVideo(VideoView.java:350)
at android.widget.VideoView.setVideoURI(VideoView.java:256)
at android.widget.VideoView.setVideoURI(VideoView.java:239)
at com.wul4.paythunder.hologram.MainActivity.cargarVideo(MainActivity.java:261)
at com.wul4.paythunder.hologram.MainActivity$6.run(MainActivity.java:395)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5466)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
My function to load the video I start it is:
public static void cargarVideo(final String video){
Uri path = Uri.parse(video);
Video.setVideoURI(path);
if(video.contains(NetworkUtils.nombreVideo(prefs.getString("listen",""))) ||
video.contains(NetworkUtils.nombreVideo(prefs.getString("talk","")))) {
Video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
Log.e("####", "onPrepared");
mp.setLooping(true);
}
});
Video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mediaPlayer) {
Log.e("####", "onCompletion");
cargarVideo(video);
}
});
}
Video.start();
}
This error does not know to be, so if someone knows or has occurred and you can lie down for a hand, he would appreciate it.
A greeting and thanks in advance
EDIT
I searched and read that the solution may lie in the method call setOnPreparedListener including within the function onPrepared the video initialization --> mp.start()
I tried it and now the same behavior seems, do not know if in the future again give the same error
Have you tried to take a look at the Life Cycle of a MediaPlayer Instance?
https://developer.android.com/reference/android/media/MediaPlayer.html
Basically from what I see, you did not properly 'reset' the MediaPlayer object so that it can properly rerun again.
Try having MediaPlayer.reset() and see if it works.
#Override
public void onCompletion(MediaPlayer mediaPlayer) {
Log.e("####", "onCompletion");
// Reset the player here
cargarVideo(video);
}

Android Robotium Testing, Runtime Exception This method can not be called from the main application thread

So I am testing my android app using Robotium and when I go to click on the item in my list it by solo.clickInList(0,1); using gives me
java.lang.RuntimeException: This method can not be called from the main application thread
at android.app.Instrumentation.validateNotAppThread(Instrumentation.java:1787)
at android.app.Instrumentation.runOnMainSync(Instrumentation.java:348)
at com.robotium.solo.Scroller.scrollListToLine(Scroller.java:326)
at com.robotium.solo.Scroller.scrollList(Scroller.java:276)
at com.robotium.solo.Scroller.scroll(Scroller.java:195)
at com.robotium.solo.Scroller.scroll(Scroller.java:156)
at com.robotium.solo.Scroller.scrollDown(Scroller.java:169)
at com.robotium.solo.Waiter.waitForView(Waiter.java:154)
at com.robotium.solo.Waiter.waitForAndGetView(Waiter.java:521)
at com.robotium.solo.Clicker.clickInList(Clicker.java:516)
at com.robotium.solo.Solo.clickInList(Solo.java:1244)
at com.teamname.tutortrader.AvailableSessionsActivityTest.testViewOneSession(AvailableSessionsActivityTest.java:119)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.access$000(InstrumentationTestCase.java:36)
at android.test.InstrumentationTestCase$2.run(InstrumentationTestCase.java:189)
at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1855)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
I am using the #UiThreadTest on top of my function.
As I found here it looks like a bug in robotium.
https://stackoverflow.com/a/20200643/6150020. You can probably do the same thing by yourself without robotium.
public void onListViewItemClick(){
Activity activity = getActivity();
final ListView listView = (ListView)activity.findViewById(android.R.id.list);
getInstrumentation().runOnMainSync(new Runnable() {
#Override
public void run() {
listView.performItemClick(listView.getAdapter().getView(0, null, null), 0, listView.getItemIdAtPosition(0));
}
});
}

Categories