I am using DailyMotion SDK in my android app to load the dailymotion videos in my app. The problem is when I play the video, Only audio is coming out but not video. Black screen is showing instead of video. Please help me this thanks in advance. My codes are
MainActivity.java
package com.example.rajeshkumarreddy.videoplayered;
import android.graphics.Color;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import com.dailymotion.android.player.sdk.PlayerWebView;
import java.util.HashMap;
import java.util.Map;
public class DailyMotionActivity extends AppCompatActivity {
PlayerWebView playerWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playerWebView=(PlayerWebView)findViewById(R.id.dm_player_web_view);
playerWebView.load("x1owz8e");
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rajeshkumarreddy.videoplayered.MainActivity">
<com.dailymotion.android.player.sdk.PlayerWebView
android:id="#+id/dm_player_web_view"
android:layout_width="match_parent"
android:layout_height="215dp">
</com.dailymotion.android.player.sdk.PlayerWebView>
</RelativeLayout>
If you are using Android Studio's emulator, this can be the cause you are not seeing the video, only audio is perceived. Use your phone, there your video probably will show (if your code is correct). So don't use the emulator to test this. Best luck.
Related
I'm running:
package com.example.projectTest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class WelcomePage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome_page);
}
}
with:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WelcomePage">
</androidx.constraintlayout.widget.ConstraintLayout>
but I'm getting the following error in the logcat when I run:
Could not get package user id: run-as: unknown package: com.example.projectTest
Could not find apks for this package: com.example.projectTest
Could not get package user id: run-as: unknown package: com.example.projectTest
Could not find apks for this package: com.example.projectTest
Failed to measure fs-verity, errno 1: /data/app/~~kWSycfQmCvKbfYx2KzxrNA==/com.example.projectTest-x4Zc9BUq0kRGdN5aX5AxXQ==/base.apk
The launch succeeds, but no app shows up on the emulator (Pixel 6 API 32). What could be the problem? Thank you.
I went to Run > Edit Configurations and set launch to a Specified Activity. I then set the specified activity and in AndroidMainfest.xml, inside the activity tag, I set exported=true. Now it works.
I'm an android novice. I'm trying to do some practice work but I am getting these two errors that I've tried for hours to fix
error: cannot find symbol variable activity_main
error: cannot find symbol variable tabLayout
Below is my MainActivity.java then after that the activity_main.xml
package com.example.rawtablayoutdemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import android.R;
public class MainActivity extends AppCompatActivity {
TabLayout tabLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabLayout = findViewById(R.id.tabLayout);
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
}
}
this is the activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
My screen that shows me the two errors
I'm sure you deep masters of code know the solution for my simple question born from a lack of understanding of Android Studio and making android apps. Please enlighten me.
Try deleting the import statement import android.R. Most probably it will work, if it doesn't try clearing and rebuilding the project from the Build -> Clean Project, then Build -> Rebuild Project.
I am a 11 year old coder and I am getting this error on my phone when I try to run the video view code so I can play a video.
The error is,"Sorry, this video cannot be played." My video I downloaded was in the raw folder under resources and the code and xml are all fine. The video format of which I am using is a mp4. Heres my code:
package com.example.lenovouser.video;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = findViewById(R.id.video_view);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.green_and_yellow_popsicle);
videoView.setVideoURI(uri);
videoView.setMediaController(new MediaController(this));
videoView.start();
}
}
And here is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.lenovouser.video.MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<VideoView
android:id="#+id/video_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
</android.support.constraint.ConstraintLayout>
Thanks for your time!
I don't see the extension of the video file. I am not sure if you can play any video from the raw, instead can you please create a assets folder an place the video file there.
videoView.setVideoPath("file:///assets/myvideo.mp4");
videoView.start();
Also make sure you are using the video format specified in the android support documentation: https://developer.android.com/guide/topics/media/media-formats#recommendations
try using this instead this uses the raw URI instead of R.raw
check this post if you are still having trouble How to play video from raw folder with Android device?
String videoPath = "android.resource://" + getPackageName() + "/raw/green_and_yellow_popsicle";
videoView.start();
how ever if you still wanna use R.raw use the code below,
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.green_and_yellow_popsicle);
videoView.setVideoURI(uri);
videoView.setMediaController(new MediaController(this));
videoView.start();
Maybe your phone`s API level under 4.1 or try another video with different format.
None of these solutions worked for me, but here you can found out how to get an URI from R.raw folder: https://stackoverflow.com/a/8616187/8187578
I am developing my first ever Android App using Eclipse.
I have the following code for my activity_main.xml view:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="biztalkers.gcmtest3.MainActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="#+id/txtToken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</FrameLayout>
I have the following code within my MainActivity.java class
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView txtToken = (TextView) findViewById(R.id.txtToken);
My problem is with tha last line in the code block "final TextView txtToken = (TextView) findViewById(R.id.txtToken);", for this I get the error "txtToken cannot be resolved or is not a field". Can anyone see what I've done wrong?
Here are the imports
package biztalkers.gcmtest3;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import biztalkers.gcmtest3.R;
The line "import biztalkers.gcmtest3.R;" is underlined red as it "cannot be resolved"
Clean and re-build your project like this,
Project -> Clean -> Check your project and press OK.
Also verify your imports.. If you have import android.R delete it.. You should only import R with the package like import com.example.R
Retry by changing the id of the TextView with a new id and also clean and rebuild the project.
Simply save every files in your project.Because R.java will be modified at the time of saving.Now you may have a TextView in your layout.But , that will not be updated in the project....
Thanks to dcharms. The problem was due to an error in one of the res files
Check your import statements. Make sure you haven't imported the android R class (i.e. import android.R) instead of your own projects R class.
I'm trying to implement a splash screen for my webview android app, so that it will display until the page is fully loaded. I was using the code from the accepted answer here but am running into some errors that I'm not sure how to solve. I assume that I'm missing a library of some sort, but I have no idea what.
The errors I'm getting are:
View cannot be resolved to a variable
error: Error: No resource found that matches the given name (at 'src' with value #drawable/vert_loading')
The code where I'm getting the view errors is:
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
findViewById(R.id.imageLoading1).setVisibility(View.GONE);
findViewById(R.id.webview).setVisibility(View.VISIBLE);
}
});
While my layout xml file is:
<ImageView
android:id="#+id/imageLoading1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:visibility="visible"
android:src="#drawable/vert_loading"
/>
My assumption is that I might be missing an import of some sort, but I wouldn't know which one. The ones I have are:
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
Any help would be greatly appreciated.
Add an drawable folder in your project res from File->New->Folder and put your drawable vert_loading in res->drawable folder. then Clean your project from Project->Clean.