davidbritch / dotnet-maui-videoplayer

A video player implementation for .NET MAUI
MIT License
82 stars 21 forks source link

"Can't play this video" error #4

Open andrijac opened 2 years ago

andrijac commented 2 years ago

First of all, thanks for doing this, great project. It is amazing that MS didn't implement Video player themselves.

I'm trying to implement your example into my project. I have mp4 file that I used in your example to try to play it as a resource file in Raw folder, it works.

I have added all the file in my project

When I try to play the file in my project, it displays dialog with message: "Can't play this video".

From output I'm getting:

[VideoView] Unable to open content: content://com.mobileapp/splashvideo.mp4
[VideoView] java.io.IOException: setDataSource failed.: status=0x80000000
[VideoView]     at android.media.MediaPlayer.nativeSetDataSource(Native Method)
[VideoView]     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1260)
[VideoView]     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1247)
[VideoView]     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1158)
[VideoView]     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1179)
[VideoView]     at android.widget.VideoView.openVideo(VideoView.java:412)
[VideoView]     at android.widget.VideoView.access$2200(VideoView.java:83)
[VideoView]     at android.widget.VideoView$7.surfaceCreated(VideoView.java:694)
[VideoView]     at android.view.SurfaceView.updateSurface(SurfaceView.java:1350)
[VideoView]     at android.view.SurfaceView.lambda$new$1$SurfaceView(SurfaceView.java:254)
[VideoView]     at android.view.SurfaceView$$ExternalSyntheticLambda2.onPreDraw(Unknown Source:2)
[VideoView]     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1112)
[VideoView]     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4171)
[VideoView]     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2893)
[VideoView]     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10445)
[VideoView]     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1108)
[VideoView]     at android.view.Choreographer.doCallbacks(Choreographer.java:866)
[VideoView]     at android.view.Choreographer.doFrame(Choreographer.java:797)
[VideoView]     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1092)
[VideoView]     at android.os.Handler.handleCallback(Handler.java:938)
[VideoView]     at android.os.Handler.dispatchMessage(Handler.java:99)
[VideoView]     at android.os.Looper.loopOnce(Looper.java:226)
[VideoView]     at android.os.Looper.loop(Looper.java:313)
[VideoView]     at android.app.ActivityThread.main(ActivityThread.java:8663)
[VideoView]     at java.lang.reflect.Method.invoke(Native Method)
[VideoView]     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
[VideoView]     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
[VideoView] Error: 1,0

Screenshot_20220901-153624

Do you have any idea what could've gone wrong?

Thanks

EdwardMcFlurry commented 2 years ago

Im also experiencing the same issue especially when Videos are loaded using CollectionView, the error message show up lets say 3 times if the CollectionView has 3 Videos. Please provide a solution regarding this.

davidbritch commented 2 years ago

Hi @andrijac

You added it to the Resources/Raw project in your single project?

davidbritch commented 2 years ago

@andrijac It's also worth checking your .csproj file that the entries for the video(s) look like:

    <ItemGroup>
      <None Remove="Resources\Raw\AndroidVideo.mp4" />
      <None Remove="Resources\Raw\AppleVideo.mp4" />
      <None Remove="Resources\Raw\WindowsVideo.mp4" />
    </ItemGroup>

I've had cases where VS produces incorrect .csproj entries (it can do a remove and an include, which is wrong).

davidbritch commented 2 years ago

Is your bundle id definitely com.mobileapp i.e. two parts to it rather than three?

andrijac commented 2 years ago

I still get same message :(

andrijac commented 2 years ago

I cleaned project before running it again.

davidbritch commented 2 years ago

Where did you change the bundle id?

andrijac commented 2 years ago

I tried reading the file my main page:

        var stream = await FileSystem.OpenAppPackageFileAsync("splashvideo.mp4");

        byte[] m_Bytes = ReadToEnd(stream);

        await this.screenNotificationService.NotifyInfo(this.logger, m_Bytes.Length.ToString());`

it worked.

andrijac commented 2 years ago

Changed in AndroidManifest and in VideoProvider.cs in Android platform folder.

andrijac commented 2 years ago

What should be format of string in VideoProvider.cs? Does it has to contain Project name? E.g.: com.mobileapp.ProjectName?

davidbritch commented 2 years ago

You also need to update it in your .csproj: https://github.com/davidbritch/dotnet-maui-videoplayer/blob/a874e5673c6ebc1894441c35773b52727a81098a/src/VideoDemos/VideoDemos.csproj#L18

AlexJinx commented 1 year ago

I got the same error, how did you solve it. I update ApplicationId for my projectname and added Resources/Raw path.it looks something like this:

<ApplicationId>com.companyname.mauiclient</ApplicationId>
<ApplicationIdGuid>9a2c7080-db10-4f4a-b1e8-a5af8c8236a3</ApplicationIdGuid>

<ItemGroup>
  <None Remove="Resources\Raw\1.mp4" />
</ItemGroup>

but it still doesn't work, please tell me how to fix it.

andrijac commented 1 year ago

I got the same error, how did you solve it. I update ApplicationId for my projectname and added Resources/Raw path.it looks something like this:

<ApplicationId>com.companyname.mauiclient</ApplicationId>
<ApplicationIdGuid>9a2c7080-db10-4f4a-b1e8-a5af8c8236a3</ApplicationIdGuid>

<ItemGroup>
  <None Remove="Resources\Raw\1.mp4" />
</ItemGroup>

but it still doesn't work, please tell me how to fix it.

I didn't solve it, I gave up :) Lucky, project got canceled. We moved back to Flutter, for now.

EdwardMcFlurry commented 1 year ago

@andrijac It’s sad that to see you going because of a simple issue that could easily be attended to by @davidbritch

AlexJinx commented 1 year ago

I solved the problem, in Platforms\Android\VideoProvider.cs file, ContentProvider Attribute value is com.companyname.projectname?

look this :[ContentProvider(new string[] { "com.companyname.mauiclient" })]

andrijac commented 1 year ago

@andrijac It’s sad that to see you going because of a simple issue that could easily be attended to by @davidbritch

It is sad that MAUI didn't had this implemented in version 1. Respect to @davidbritch for trying to solve it.

EdwardMcFlurry commented 1 year ago

@andrijac I agree that @davidbritch did a fantastic job with his implementation, its just that the MediaElement is 'slowly' progressing but I personally wanted to expose this incredible work that is already done by @davidbritch for the simplicity of addressing a specific needs that developers have.

Can I kindly share about 3 links of simple videos uploaded on my Azure Blob Storage using this project to check why there's error of 'Can't play this video' only on Android.