How can I play a local video in my Android project?

Kim Strasser 1,321 Reputation points
2024-07-22T10:21:03.7933333+00:00

I have created a new folder named Assets in my Android project. Then I have added the file Testvideo1.mp4 to this folder and set the build action to AndroidAsset. But the video is not playing when I use this code.

How can I play a local video in my Android project?

await CrossMediaManager.Current.PlayFromResource("Assets:///Testvideo1.mp4");

Bildschirmfoto 2024-07-22 um 12.19.40

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,142 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2024-07-23T03:09:17.6366667+00:00

    Hello,

    I test your code await CrossMediaManager.Current.PlayFromResource("Assets:///Testvideo1.mp4");, I cannot play as well, Please report an issue in XamarinMediaManager GitHub repo

    However, I find a workaround to play the local video file.

    Firstly, you can create raw folder in the Resources folder, then copy your video in the raw folder and make sure this video's **BuildAction ** is AndroidResource.

    Then. You can invoke code about playing the local video twice like following lines. This video could be played.

    await CrossMediaManager.Android.PlayFromResource(Resource.Raw.test1.ToString());
    await CrossMediaManager.Android.PlayFromResource(Resource.Raw.test1.ToString());
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.