Playing local mp4 file in electron









up vote
5
down vote

favorite
1












I am trying to develop a small application in which I first capture screen via aperture package and then try to show it in the screen using video tag.



I capture screen via:



import apertureConstructor from 'aperture';
const aperture = apertureConstructor();

const options =
fps: 30
;

(async () =>
await aperture.startRecording(options);
setTimeout(async () =>
this.captureUrl = await aperture.stopRecording();
, 3000)
)();


Please ignore the mess. Aperture package writes captured video to disk and eventually, I have the path to this file in captureUrl. It is something like this:



/var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-79999m0uOszQK0zaC.mp4



I can verify that this file exists and plays just fine, if I type: file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-79999m0uOszQK0zaC.mp4 to Google Chrome address bar.



So I try to use this address as the source of my video tag like this:



 <video control autoplay>
<source src="/var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4" type="video/mp4">
</video>


Which complains that file is not there (404):



GET http://localhost:9080/var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4 404 (Not Found)


And yes, it indeed tries to go to localhost:9080 because in this case it is my development server host and there is no such a file.



So I decide to add file://...



<video controls autoplay>
<source src="file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4" type="video/mp4">
</video>


This time it says:



Not allowed to load local resource: file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-80041e3SlBZUNphLM.mp4


:/



I wonder if I missed something that makes "file://" secure or something else.



I also thought about reading the whole file via "fs" and base64'ing it providing video as data: but as this video file might be large, I feel like I shouldn't go that way.



As I am new to electron I hope I miss something basic. Any help is appreciated. Thanks!










share|improve this question

























    up vote
    5
    down vote

    favorite
    1












    I am trying to develop a small application in which I first capture screen via aperture package and then try to show it in the screen using video tag.



    I capture screen via:



    import apertureConstructor from 'aperture';
    const aperture = apertureConstructor();

    const options =
    fps: 30
    ;

    (async () =>
    await aperture.startRecording(options);
    setTimeout(async () =>
    this.captureUrl = await aperture.stopRecording();
    , 3000)
    )();


    Please ignore the mess. Aperture package writes captured video to disk and eventually, I have the path to this file in captureUrl. It is something like this:



    /var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-79999m0uOszQK0zaC.mp4



    I can verify that this file exists and plays just fine, if I type: file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-79999m0uOszQK0zaC.mp4 to Google Chrome address bar.



    So I try to use this address as the source of my video tag like this:



     <video control autoplay>
    <source src="/var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4" type="video/mp4">
    </video>


    Which complains that file is not there (404):



    GET http://localhost:9080/var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4 404 (Not Found)


    And yes, it indeed tries to go to localhost:9080 because in this case it is my development server host and there is no such a file.



    So I decide to add file://...



    <video controls autoplay>
    <source src="file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4" type="video/mp4">
    </video>


    This time it says:



    Not allowed to load local resource: file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-80041e3SlBZUNphLM.mp4


    :/



    I wonder if I missed something that makes "file://" secure or something else.



    I also thought about reading the whole file via "fs" and base64'ing it providing video as data: but as this video file might be large, I feel like I shouldn't go that way.



    As I am new to electron I hope I miss something basic. Any help is appreciated. Thanks!










    share|improve this question























      up vote
      5
      down vote

      favorite
      1









      up vote
      5
      down vote

      favorite
      1






      1





      I am trying to develop a small application in which I first capture screen via aperture package and then try to show it in the screen using video tag.



      I capture screen via:



      import apertureConstructor from 'aperture';
      const aperture = apertureConstructor();

      const options =
      fps: 30
      ;

      (async () =>
      await aperture.startRecording(options);
      setTimeout(async () =>
      this.captureUrl = await aperture.stopRecording();
      , 3000)
      )();


      Please ignore the mess. Aperture package writes captured video to disk and eventually, I have the path to this file in captureUrl. It is something like this:



      /var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-79999m0uOszQK0zaC.mp4



      I can verify that this file exists and plays just fine, if I type: file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-79999m0uOszQK0zaC.mp4 to Google Chrome address bar.



      So I try to use this address as the source of my video tag like this:



       <video control autoplay>
      <source src="/var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4" type="video/mp4">
      </video>


      Which complains that file is not there (404):



      GET http://localhost:9080/var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4 404 (Not Found)


      And yes, it indeed tries to go to localhost:9080 because in this case it is my development server host and there is no such a file.



      So I decide to add file://...



      <video controls autoplay>
      <source src="file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4" type="video/mp4">
      </video>


      This time it says:



      Not allowed to load local resource: file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-80041e3SlBZUNphLM.mp4


      :/



      I wonder if I missed something that makes "file://" secure or something else.



      I also thought about reading the whole file via "fs" and base64'ing it providing video as data: but as this video file might be large, I feel like I shouldn't go that way.



      As I am new to electron I hope I miss something basic. Any help is appreciated. Thanks!










      share|improve this question













      I am trying to develop a small application in which I first capture screen via aperture package and then try to show it in the screen using video tag.



      I capture screen via:



      import apertureConstructor from 'aperture';
      const aperture = apertureConstructor();

      const options =
      fps: 30
      ;

      (async () =>
      await aperture.startRecording(options);
      setTimeout(async () =>
      this.captureUrl = await aperture.stopRecording();
      , 3000)
      )();


      Please ignore the mess. Aperture package writes captured video to disk and eventually, I have the path to this file in captureUrl. It is something like this:



      /var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-79999m0uOszQK0zaC.mp4



      I can verify that this file exists and plays just fine, if I type: file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-79999m0uOszQK0zaC.mp4 to Google Chrome address bar.



      So I try to use this address as the source of my video tag like this:



       <video control autoplay>
      <source src="/var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4" type="video/mp4">
      </video>


      Which complains that file is not there (404):



      GET http://localhost:9080/var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4 404 (Not Found)


      And yes, it indeed tries to go to localhost:9080 because in this case it is my development server host and there is no such a file.



      So I decide to add file://...



      <video controls autoplay>
      <source src="file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-8004145a2o4gugbVV.mp4" type="video/mp4">
      </video>


      This time it says:



      Not allowed to load local resource: file:///var/folders/29/08gshk3n4mlbbcjnm1m5xyy40000gp/T/tmp-80041e3SlBZUNphLM.mp4


      :/



      I wonder if I missed something that makes "file://" secure or something else.



      I also thought about reading the whole file via "fs" and base64'ing it providing video as data: but as this video file might be large, I feel like I shouldn't go that way.



      As I am new to electron I hope I miss something basic. Any help is appreciated. Thanks!







      macos html5-video electron






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 7 '17 at 19:19









      Umut Benzer

      2,05522347




      2,05522347






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          It's nice to see a question from someone familiar here. :)



          I'd suggest you to disable web security preference within BrowserWindow. Also there is an issue related to this topic.






          share|improve this answer



























            up vote
            0
            down vote













            I recently ran into the same issue. You can set (in main process):



            webPreferences: 
            webSecurity: false



            This will allow you to load file:// urls from a user's HDD. However, this is really bad practice as it opens up security.



            The accepted way would be to:



            webPreferences: 
            webSecurity: true



            And, then from your main process create a web server that serves up the files you want.



            In your main process:



            const http = require('http')
            const express = require('express')
            const expressApp = express()
            const cors = require('cors')
            const router = express.Router()


            Then do the following code:



            expressApp.use(cors())

            router.get('/file/:name', function (req, res)
            let filename = req.params.name
            res.sendFile(filename)
            )

            expressApp.use('/', router)

            http.createServer(expressApp).listen(8000)


            Now, in your js/html in the renderer code, you can set src in the video tag to be:



            'http://localhost:8000/file/' + filename





            share|improve this answer




















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45554249%2fplaying-local-mp4-file-in-electron%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote



              accepted










              It's nice to see a question from someone familiar here. :)



              I'd suggest you to disable web security preference within BrowserWindow. Also there is an issue related to this topic.






              share|improve this answer
























                up vote
                0
                down vote



                accepted










                It's nice to see a question from someone familiar here. :)



                I'd suggest you to disable web security preference within BrowserWindow. Also there is an issue related to this topic.






                share|improve this answer






















                  up vote
                  0
                  down vote



                  accepted







                  up vote
                  0
                  down vote



                  accepted






                  It's nice to see a question from someone familiar here. :)



                  I'd suggest you to disable web security preference within BrowserWindow. Also there is an issue related to this topic.






                  share|improve this answer












                  It's nice to see a question from someone familiar here. :)



                  I'd suggest you to disable web security preference within BrowserWindow. Also there is an issue related to this topic.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 8 '17 at 19:42









                  Ali BARIN

                  1,070815




                  1,070815






















                      up vote
                      0
                      down vote













                      I recently ran into the same issue. You can set (in main process):



                      webPreferences: 
                      webSecurity: false



                      This will allow you to load file:// urls from a user's HDD. However, this is really bad practice as it opens up security.



                      The accepted way would be to:



                      webPreferences: 
                      webSecurity: true



                      And, then from your main process create a web server that serves up the files you want.



                      In your main process:



                      const http = require('http')
                      const express = require('express')
                      const expressApp = express()
                      const cors = require('cors')
                      const router = express.Router()


                      Then do the following code:



                      expressApp.use(cors())

                      router.get('/file/:name', function (req, res)
                      let filename = req.params.name
                      res.sendFile(filename)
                      )

                      expressApp.use('/', router)

                      http.createServer(expressApp).listen(8000)


                      Now, in your js/html in the renderer code, you can set src in the video tag to be:



                      'http://localhost:8000/file/' + filename





                      share|improve this answer
























                        up vote
                        0
                        down vote













                        I recently ran into the same issue. You can set (in main process):



                        webPreferences: 
                        webSecurity: false



                        This will allow you to load file:// urls from a user's HDD. However, this is really bad practice as it opens up security.



                        The accepted way would be to:



                        webPreferences: 
                        webSecurity: true



                        And, then from your main process create a web server that serves up the files you want.



                        In your main process:



                        const http = require('http')
                        const express = require('express')
                        const expressApp = express()
                        const cors = require('cors')
                        const router = express.Router()


                        Then do the following code:



                        expressApp.use(cors())

                        router.get('/file/:name', function (req, res)
                        let filename = req.params.name
                        res.sendFile(filename)
                        )

                        expressApp.use('/', router)

                        http.createServer(expressApp).listen(8000)


                        Now, in your js/html in the renderer code, you can set src in the video tag to be:



                        'http://localhost:8000/file/' + filename





                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          I recently ran into the same issue. You can set (in main process):



                          webPreferences: 
                          webSecurity: false



                          This will allow you to load file:// urls from a user's HDD. However, this is really bad practice as it opens up security.



                          The accepted way would be to:



                          webPreferences: 
                          webSecurity: true



                          And, then from your main process create a web server that serves up the files you want.



                          In your main process:



                          const http = require('http')
                          const express = require('express')
                          const expressApp = express()
                          const cors = require('cors')
                          const router = express.Router()


                          Then do the following code:



                          expressApp.use(cors())

                          router.get('/file/:name', function (req, res)
                          let filename = req.params.name
                          res.sendFile(filename)
                          )

                          expressApp.use('/', router)

                          http.createServer(expressApp).listen(8000)


                          Now, in your js/html in the renderer code, you can set src in the video tag to be:



                          'http://localhost:8000/file/' + filename





                          share|improve this answer












                          I recently ran into the same issue. You can set (in main process):



                          webPreferences: 
                          webSecurity: false



                          This will allow you to load file:// urls from a user's HDD. However, this is really bad practice as it opens up security.



                          The accepted way would be to:



                          webPreferences: 
                          webSecurity: true



                          And, then from your main process create a web server that serves up the files you want.



                          In your main process:



                          const http = require('http')
                          const express = require('express')
                          const expressApp = express()
                          const cors = require('cors')
                          const router = express.Router()


                          Then do the following code:



                          expressApp.use(cors())

                          router.get('/file/:name', function (req, res)
                          let filename = req.params.name
                          res.sendFile(filename)
                          )

                          expressApp.use('/', router)

                          http.createServer(expressApp).listen(8000)


                          Now, in your js/html in the renderer code, you can set src in the video tag to be:



                          'http://localhost:8000/file/' + filename






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 10 at 20:23









                          Hawkeye64

                          296311




                          296311



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45554249%2fplaying-local-mp4-file-in-electron%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Top Tejano songwriter Luis Silva dead of heart attack at 64

                              政党

                              天津地下鉄3号線