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
Related
I am doing a java to c# transition, and need help.
in Visual Studio 2019 Pro, Android 9.0 (Pie), I am doing this example:
https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-a-jar
The goal is later to convert my java libs to c# for my big project.
I follow the instructions to the letter, and when I come to the part where I need to create an ImageView, there is the problem. Once I create the ImageView, it has an android:src field, something like this (auto generated):
android:src="#drawable/icon"
The problem here, is when I remove that field, in the VS designer, the ImageView disappears and it does not matter if I have the c# code or not, even when I set the srec to:""
Bellow is literally all the code in MainActivity:
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
using Com.Squareup.Picasso;
namespace App3
{
[Activity(Label = "#string/app_name", Theme = "#style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
/***********************************************************************/
/**Picasso Code**/
ImageView imageView = FindViewById<ImageView>(Resource.Id.imageView1);
// Use the Picasso jar library to load and display this image:
Picasso.With(this)
.Load("http://i.imgur.com/DvpvklR.jpg")
.Into(imageView);
/**End Ff Picasso Code**/
/***********************************************************************/
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:src="#drawable/icon" <!-- this line -->
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView1" />
</LinearLayout>
The app does nothing, and in the emulator, the ImageView is empty.
And there is no error, or anything.
If you need anything more, please let me know.
I hope you can help me, if not, thank you for your time.
Edit 1:
It seems, the problem lies in the C# code.
If I add the android:src field, it still does not show up on the emulator, but when I remove the code (the Picasso code) than the image(drawable/icon) shows. Still no error!!
try this
<ImageView
android:src="#drawable/icon" <!-- this line -->
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="50px"
android:minHeight="50px"
android:id="#+id/imageView1" />
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.
I'm trying to add ActionBar-PushToRefresh to my project. I've followed the instructions from Chris Banes Github there: Github ActionBar-PullToRefresh
Here is my view from which I want to enable the PullToRefresh feature:
<uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ptr_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Your content, here we're using a ScrollView -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="PULLTOREFRESH THE VIEW"
android:id="#+id/textView1" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>
</uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout>
And here is my Activity to display the view:
package com.Test.pulltorefresh;
import android.app.Activity;
import android.os.Bundle;
import uk.co.senab.actionbarpulltorefresh.library.ActionBarPullToRefresh;
import uk.co.senab.actionbarpulltorefresh.library.Options;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout;
public class MainActivity extends Activity {
private PullToRefreshLayout mPullToRefreshLayout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Now find the PullToRefreshLayout to setup
mPullToRefreshLayout = (PullToRefreshLayout) findViewById(R.id.ptr_layout);
// Now setup the PullToRefreshLayout
ActionBarPullToRefresh.from(this)
// Mark All Children as pullable
.allChildrenArePullable()
// Set the OnRefreshListener
//.listener(this)
// Finally commit the setup to our PullToRefreshLayout
.setup(mPullToRefreshLayout);
}
}
When I launch my app, I got the blank view but nothing happens when I'm trying to PushToRefresh my view. Can someone show me how to fix it, I know that I've missed something. Thanks.
I may be a bit partial but...
you could consider using this
Maybe you have already achieved the functionality, but in the code above, you have commented out the line which defines the action on pulling the view.
//.listener(this)
You should uncomment this line and define the listener method, which should be called when the view is pulled.
The following classes could not be instantiated:
- com.amazon.device.ads.AdLayout (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
java.lang.NoClassDefFoundError: Could not initialize class android.os.Environment
at com.amazon.device.ads.DebugProperties.readDebugProperties(DebugProperties.java:75)
at com.amazon.device.ads.InternalAdRegistration.<init>(InternalAdRegistration.java:52)
at com.amazon.device.ads.InternalAdRegistration.getInstance(InternalAdRegistration.java:64)
at com.amazon.device.ads.AdLayout.initialize(AdLayout.java:185)
at com.amazon.device.ads.AdLayout.initialize(AdLayout.java:176)
at com.amazon.device.ads.AdLayout.<init>(AdLayout.java:120)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0( at sun.reflect.NativeConstructorAccessorImpl.newInstance( at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( at java.lang.reflect.Constructor.newInstance( at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:422)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:179)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:755)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:373)
My main.xml looks like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Amazon="http://schemas.android.com/apk/lib/com.amazon.device.ads"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="top|center_horizontal" >
<com.amazon.device.ads.AdLayout
android:id="#+id/myAdView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
My MainActivity.java is this
import com.amazon.device.ads.AdLayout;
import com.amazon.device.ads.AdRegistration;
import com.amazon.device.ads.AdTargetingOptions;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preferences = PreferenceManager.getDefaultSharedPreferences(this);
int defaultValue = R.drawable.blue;
int themedefault = ThemeChanger.THEME_BLUE;
appliedtheme = preferences.getInt("mytheme", themedefault);
ThemeChanger.onActivityCreateSetTheme(this, appliedtheme);
setContentView(R.layout.main);
AdRegistration.setAppKey("Application_Key");
this.adView = (AdLayout) findViewById(R.id.myAdView);
this.adView.loadAd(new AdTargetingOptions());
button1 = preferences.getInt("DigitButtonStyle", defaultValue);
buttonmadd = preferences.getInt("MemoryButtonStyle", defaultValue);
buttoncos = preferences.getInt("FunctionButtonStyle", defaultValue);
I had the same issue and followed Amazon developer guide. To solve this issue, just copy amazon library and paste it in your libs folder and than run.
It's a known issue in Eclipse ADT plugin, even if you use View.isInEditMode(), in some cases, it crashes in recent API versions (higher than 18). It's fixed in Android Studio.
If you want to see Layout Preview, you can try with different API version lower than 19.
Check the screenshot. It's using API 18. (Red box is Amazon AdLayout)
I have a hindi content based android app and have used devangiri font from Android API 16 SDK and renamed as hindi.ttf. The text renders fine on API level 16 and 17 but simply tears apart in Android API level 15 and lower.
Is there any why I can fix that without removing support for lower API levels. My code for setting textview is:
import android.app.Activity;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.GestureDetector;
import android.widget.TextView;
public class Prayer extends Activity {
// TextSwitcher vs;
GestureDetector gestureDetector;
static Tips tip = null;
static StringBuilder quesString = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prayer);
TextView tv1 = (TextView) findViewById(R.id.textView1);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/hindi.ttf");
tv1.setTypeface(tf);
tv1.setText("श्री");
tv1.setPaintFlags(tv1.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
}
Layout XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C5C6E1"
tools:context=".Prayer" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TextView>
</RelativeLayout>
Current:
Expected:
I faced exactly similar issue when I was developing an Hindi app. However, the error resolved when I changed the font files.
Also, IMHO the device simply replaces UTF-8 symbols in text with corresponding symbols in font files. In this case, its showing a completely different symbol altogether. So, the problem should be with font files.
Give me your e-mail in case you want to use my font files.
For Hindi support, I backported the DroidSansDevanagari-Regular.ttf font that was added in Jellybean. You can find all the Jellybean Android fonts in you SDK directory under:
/<Android SDK Dir>/platforms/android-16/data/fonts
If you are still seeing tearing on 4.0.2, you can try:
tv1.setPaintFlags(tv1.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
When setting a dynamic textSize use this:
tv1.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelOffset(R.dimen.questionTEXT));