Luis Lema
Luis Lema

Reputation: 307

Xamarin Forms Android error CS0117: 'Resource.Drawable' does not contain a definition for "...."

I am trying to build a splash screen with a video in Xamarin Forms Android on Visual Studio 2019. Xamarin Forms version 4.7.0.968. I am trying to open a video file "Intro.mp4" located in the Resources/drawable folder. The video's build action is set to "AndroidAsset" and it already contains an id in Resource.designer.cs inside the Drawable class:image's resource id

Here's where I am referencing the file:

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{        
    protected override void OnCreate(Bundle savedInstanceState)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(savedInstanceState);

        StartService(new Android.Content.Intent(this, typeof(AudioService)));

        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

        SetContentView(Resource.Layout.Splash);
        var videoView = FindViewById<VideoView>(Resource.Id.splashVideo);

        string videoPath = $"android.resource://{Application.PackageName}/{Resource.Drawable.Intro}";
        videoView.SetVideoPath(videoPath);
        videoView.Start();            

        LoadApplication(new App());
    }

When I build the project I get this error: "error CS0117: 'Resource.Drawable' does not contain a definition for 'Intro'". I tried several suggestions I found in the forums, delete the obj and bin folders, restart Visual Studio, restart my pc, uninstall Xamarin and reinstall it, roll back to the previous Xamarin packages in NuGet Package Manager but nothing is helping. I am not sure if it's a Xamarin bug or an issue with my code. Any help will be much appreciated.

Upvotes: 0

Views: 937

Answers (1)

Jason
Jason

Reputation: 89082

an Asset and a Resource are not the same thing - if you want a resource, the build action should be Android Resource

Upvotes: 2

Related Questions