Can i use table column in Sqlite database as a resource variable?












0















i have some code like this



Orignally:



String path = "android.resource://" + getPackageName() + "/" + R.raw.video;

videoView.setVideoURI(Uri.parse(path));

videoView.requestFocus();
videoView.start();


And the videoView works perfectly.



Then I changed the code into



String path = "android.resource://" + getPackageName() + "/" + Dbhelper.COLUMN_Path;

videoView.setVideoURI(Uri.parse(path));

videoView.requestFocus();
videoView.start();


I stored "R.raw.video" into the COLUMN.Path in the database. It works. But why the videoView doesnt work? It told me "Cant play this video"










share|improve this question



























    0















    i have some code like this



    Orignally:



    String path = "android.resource://" + getPackageName() + "/" + R.raw.video;

    videoView.setVideoURI(Uri.parse(path));

    videoView.requestFocus();
    videoView.start();


    And the videoView works perfectly.



    Then I changed the code into



    String path = "android.resource://" + getPackageName() + "/" + Dbhelper.COLUMN_Path;

    videoView.setVideoURI(Uri.parse(path));

    videoView.requestFocus();
    videoView.start();


    I stored "R.raw.video" into the COLUMN.Path in the database. It works. But why the videoView doesnt work? It told me "Cant play this video"










    share|improve this question

























      0












      0








      0








      i have some code like this



      Orignally:



      String path = "android.resource://" + getPackageName() + "/" + R.raw.video;

      videoView.setVideoURI(Uri.parse(path));

      videoView.requestFocus();
      videoView.start();


      And the videoView works perfectly.



      Then I changed the code into



      String path = "android.resource://" + getPackageName() + "/" + Dbhelper.COLUMN_Path;

      videoView.setVideoURI(Uri.parse(path));

      videoView.requestFocus();
      videoView.start();


      I stored "R.raw.video" into the COLUMN.Path in the database. It works. But why the videoView doesnt work? It told me "Cant play this video"










      share|improve this question














      i have some code like this



      Orignally:



      String path = "android.resource://" + getPackageName() + "/" + R.raw.video;

      videoView.setVideoURI(Uri.parse(path));

      videoView.requestFocus();
      videoView.start();


      And the videoView works perfectly.



      Then I changed the code into



      String path = "android.resource://" + getPackageName() + "/" + Dbhelper.COLUMN_Path;

      videoView.setVideoURI(Uri.parse(path));

      videoView.requestFocus();
      videoView.start();


      I stored "R.raw.video" into the COLUMN.Path in the database. It works. But why the videoView doesnt work? It told me "Cant play this video"







      android database sqlite android-studio






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 17:10









      dead poohdead pooh

      31




      31
























          1 Answer
          1






          active

          oldest

          votes


















          0














          If you stored the integer value of R.raw.video then this is an integer number that the system assigned the this resource video file when the project was compiled.

          I believe you retrieved it at runtime and saved it to the db.

          This integer value is valid as long as you use the apk built at the time of that compilation.

          But if you make any changes (especially to your resources) and recompile, there is no guarantee that this value will still be valid and correspond to this resource, because resource values may be reassigned new values.

          So your way is wrong.


          One way to solve this issue is to store in the db the string "name" of the resource, meaning: "video" (not the fully qualified R.raw.video).

          Now when you want to retrieve the file from the raw folder,

          after you get the value from the db to a variable like videoName, do this:



          int id = getResources().getIdentifier(videoName, "raw", getPackageName());


          This is the way to retrieve the integer id of the resource named videoName which resides in the raw folder.

          If your code is not inside an activity you need to supply a valid Context, like this:



          int id = context.getResources().getIdentifier(videoName, "raw", context.getPackageName());


          and finally:



          String path = "android.resource://" + getPackageName() + "/" + id;


          Edit
          If you stored R.raw.video as a string in db, then this cannot help you because this full string has no value assigned to it as I explained earlier.






          share|improve this answer


























          • I completely do as you said, but still it doesn't work!! Why?

            – dead pooh
            Nov 22 '18 at 17:57













          • i have already sure that i got the correct value from the db, exactly the same name of that resource,

            – dead pooh
            Nov 22 '18 at 18:00











          • Then put a breakpoint at the line int id =..... and check if you get a valid id and then if this line String path = "android.resource://" + getPackageName() + "/" + id; is valid

            – forpas
            Nov 22 '18 at 18:02











          • the id becomes 0

            – dead pooh
            Nov 22 '18 at 18:20











          • there for it becomes android.resource://getPackageName()/0

            – dead pooh
            Nov 22 '18 at 18:23











          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',
          autoActivateHeartbeat: false,
          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%2f53435651%2fcan-i-use-table-column-in-sqlite-database-as-a-resource-variable%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          If you stored the integer value of R.raw.video then this is an integer number that the system assigned the this resource video file when the project was compiled.

          I believe you retrieved it at runtime and saved it to the db.

          This integer value is valid as long as you use the apk built at the time of that compilation.

          But if you make any changes (especially to your resources) and recompile, there is no guarantee that this value will still be valid and correspond to this resource, because resource values may be reassigned new values.

          So your way is wrong.


          One way to solve this issue is to store in the db the string "name" of the resource, meaning: "video" (not the fully qualified R.raw.video).

          Now when you want to retrieve the file from the raw folder,

          after you get the value from the db to a variable like videoName, do this:



          int id = getResources().getIdentifier(videoName, "raw", getPackageName());


          This is the way to retrieve the integer id of the resource named videoName which resides in the raw folder.

          If your code is not inside an activity you need to supply a valid Context, like this:



          int id = context.getResources().getIdentifier(videoName, "raw", context.getPackageName());


          and finally:



          String path = "android.resource://" + getPackageName() + "/" + id;


          Edit
          If you stored R.raw.video as a string in db, then this cannot help you because this full string has no value assigned to it as I explained earlier.






          share|improve this answer


























          • I completely do as you said, but still it doesn't work!! Why?

            – dead pooh
            Nov 22 '18 at 17:57













          • i have already sure that i got the correct value from the db, exactly the same name of that resource,

            – dead pooh
            Nov 22 '18 at 18:00











          • Then put a breakpoint at the line int id =..... and check if you get a valid id and then if this line String path = "android.resource://" + getPackageName() + "/" + id; is valid

            – forpas
            Nov 22 '18 at 18:02











          • the id becomes 0

            – dead pooh
            Nov 22 '18 at 18:20











          • there for it becomes android.resource://getPackageName()/0

            – dead pooh
            Nov 22 '18 at 18:23
















          0














          If you stored the integer value of R.raw.video then this is an integer number that the system assigned the this resource video file when the project was compiled.

          I believe you retrieved it at runtime and saved it to the db.

          This integer value is valid as long as you use the apk built at the time of that compilation.

          But if you make any changes (especially to your resources) and recompile, there is no guarantee that this value will still be valid and correspond to this resource, because resource values may be reassigned new values.

          So your way is wrong.


          One way to solve this issue is to store in the db the string "name" of the resource, meaning: "video" (not the fully qualified R.raw.video).

          Now when you want to retrieve the file from the raw folder,

          after you get the value from the db to a variable like videoName, do this:



          int id = getResources().getIdentifier(videoName, "raw", getPackageName());


          This is the way to retrieve the integer id of the resource named videoName which resides in the raw folder.

          If your code is not inside an activity you need to supply a valid Context, like this:



          int id = context.getResources().getIdentifier(videoName, "raw", context.getPackageName());


          and finally:



          String path = "android.resource://" + getPackageName() + "/" + id;


          Edit
          If you stored R.raw.video as a string in db, then this cannot help you because this full string has no value assigned to it as I explained earlier.






          share|improve this answer


























          • I completely do as you said, but still it doesn't work!! Why?

            – dead pooh
            Nov 22 '18 at 17:57













          • i have already sure that i got the correct value from the db, exactly the same name of that resource,

            – dead pooh
            Nov 22 '18 at 18:00











          • Then put a breakpoint at the line int id =..... and check if you get a valid id and then if this line String path = "android.resource://" + getPackageName() + "/" + id; is valid

            – forpas
            Nov 22 '18 at 18:02











          • the id becomes 0

            – dead pooh
            Nov 22 '18 at 18:20











          • there for it becomes android.resource://getPackageName()/0

            – dead pooh
            Nov 22 '18 at 18:23














          0












          0








          0







          If you stored the integer value of R.raw.video then this is an integer number that the system assigned the this resource video file when the project was compiled.

          I believe you retrieved it at runtime and saved it to the db.

          This integer value is valid as long as you use the apk built at the time of that compilation.

          But if you make any changes (especially to your resources) and recompile, there is no guarantee that this value will still be valid and correspond to this resource, because resource values may be reassigned new values.

          So your way is wrong.


          One way to solve this issue is to store in the db the string "name" of the resource, meaning: "video" (not the fully qualified R.raw.video).

          Now when you want to retrieve the file from the raw folder,

          after you get the value from the db to a variable like videoName, do this:



          int id = getResources().getIdentifier(videoName, "raw", getPackageName());


          This is the way to retrieve the integer id of the resource named videoName which resides in the raw folder.

          If your code is not inside an activity you need to supply a valid Context, like this:



          int id = context.getResources().getIdentifier(videoName, "raw", context.getPackageName());


          and finally:



          String path = "android.resource://" + getPackageName() + "/" + id;


          Edit
          If you stored R.raw.video as a string in db, then this cannot help you because this full string has no value assigned to it as I explained earlier.






          share|improve this answer















          If you stored the integer value of R.raw.video then this is an integer number that the system assigned the this resource video file when the project was compiled.

          I believe you retrieved it at runtime and saved it to the db.

          This integer value is valid as long as you use the apk built at the time of that compilation.

          But if you make any changes (especially to your resources) and recompile, there is no guarantee that this value will still be valid and correspond to this resource, because resource values may be reassigned new values.

          So your way is wrong.


          One way to solve this issue is to store in the db the string "name" of the resource, meaning: "video" (not the fully qualified R.raw.video).

          Now when you want to retrieve the file from the raw folder,

          after you get the value from the db to a variable like videoName, do this:



          int id = getResources().getIdentifier(videoName, "raw", getPackageName());


          This is the way to retrieve the integer id of the resource named videoName which resides in the raw folder.

          If your code is not inside an activity you need to supply a valid Context, like this:



          int id = context.getResources().getIdentifier(videoName, "raw", context.getPackageName());


          and finally:



          String path = "android.resource://" + getPackageName() + "/" + id;


          Edit
          If you stored R.raw.video as a string in db, then this cannot help you because this full string has no value assigned to it as I explained earlier.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 '18 at 17:52

























          answered Nov 22 '18 at 17:40









          forpasforpas

          11.9k3424




          11.9k3424













          • I completely do as you said, but still it doesn't work!! Why?

            – dead pooh
            Nov 22 '18 at 17:57













          • i have already sure that i got the correct value from the db, exactly the same name of that resource,

            – dead pooh
            Nov 22 '18 at 18:00











          • Then put a breakpoint at the line int id =..... and check if you get a valid id and then if this line String path = "android.resource://" + getPackageName() + "/" + id; is valid

            – forpas
            Nov 22 '18 at 18:02











          • the id becomes 0

            – dead pooh
            Nov 22 '18 at 18:20











          • there for it becomes android.resource://getPackageName()/0

            – dead pooh
            Nov 22 '18 at 18:23



















          • I completely do as you said, but still it doesn't work!! Why?

            – dead pooh
            Nov 22 '18 at 17:57













          • i have already sure that i got the correct value from the db, exactly the same name of that resource,

            – dead pooh
            Nov 22 '18 at 18:00











          • Then put a breakpoint at the line int id =..... and check if you get a valid id and then if this line String path = "android.resource://" + getPackageName() + "/" + id; is valid

            – forpas
            Nov 22 '18 at 18:02











          • the id becomes 0

            – dead pooh
            Nov 22 '18 at 18:20











          • there for it becomes android.resource://getPackageName()/0

            – dead pooh
            Nov 22 '18 at 18:23

















          I completely do as you said, but still it doesn't work!! Why?

          – dead pooh
          Nov 22 '18 at 17:57







          I completely do as you said, but still it doesn't work!! Why?

          – dead pooh
          Nov 22 '18 at 17:57















          i have already sure that i got the correct value from the db, exactly the same name of that resource,

          – dead pooh
          Nov 22 '18 at 18:00





          i have already sure that i got the correct value from the db, exactly the same name of that resource,

          – dead pooh
          Nov 22 '18 at 18:00













          Then put a breakpoint at the line int id =..... and check if you get a valid id and then if this line String path = "android.resource://" + getPackageName() + "/" + id; is valid

          – forpas
          Nov 22 '18 at 18:02





          Then put a breakpoint at the line int id =..... and check if you get a valid id and then if this line String path = "android.resource://" + getPackageName() + "/" + id; is valid

          – forpas
          Nov 22 '18 at 18:02













          the id becomes 0

          – dead pooh
          Nov 22 '18 at 18:20





          the id becomes 0

          – dead pooh
          Nov 22 '18 at 18:20













          there for it becomes android.resource://getPackageName()/0

          – dead pooh
          Nov 22 '18 at 18:23





          there for it becomes android.resource://getPackageName()/0

          – dead pooh
          Nov 22 '18 at 18:23


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435651%2fcan-i-use-table-column-in-sqlite-database-as-a-resource-variable%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

          Costa Masnaga

          Fotorealismo

          Sidney Franklin