Differences between mpmovieplayerviewcontroller and ios5.0 when playing a media file-Modify

Source: Internet
Author: User

Jacky Shin: nsurl * mediafileurl = [nsurl urlwithstring: urlstr];

Nsstring * moviepath = [[nsbundlemainbundle] pathforresource: @ "head" oftype: @ "mov"];

Nsurl * localurl = [[nsurl alloc] initwithstring: moviepath];

Nsurl * localurl1 = [nsurl urlwithstring: moviepath];

Nsurl * localurl2 = [nsurl fileurlwithpath: moviepath];

Nslog (@ "localurl =%@, localurl1 =%@, localurl2 =%@", localurl, localurl1, localurl2 );

Output:

15:26:57. 342 mmp l [4174: 907]

Localurl =/var/mobile/applications/B89AE103-A5BF-4EFA-B3AE-B3D40DA00BD2/matrix. APP/head. mov, localurl1 =/var/mobile/applications/B89AE103-A5BF-4EFA-B3AE-B3D40DA00BD2/matrix. APP/head. mov,
Localurl2 = file: // localhost/var/mobile/applications/B89AE103-A5BF-4EFA-B3AE-B3D40DA00BD2/matrix. APP/head. mov

Lab proof,

1. If the local file is played, the above localurl and localurl1 will cause abnormal playback. The playback page will pop up and then automatically return it as if the playback is complete. However, localurl2 can be used for normal playback. (Test on ipad2 ios6)

2. If you are playing a network file, use the following code in the official example of Apple movieplayer:

Nsurl * themovieurl = [nsurl
Urlwithstring: Self. movieurltextfield. Text];

Is the urlwithstring method used. If it is changed to initwithstring, it can be played normally. If it is changed to fileurlwithpath, it will fail.

The following parts are from the Internet.

Sample Code:

Nsstring * urlstr = @ "http://videourl.com ";
Nsurl * mediafileurl = [nsurl urlwithstring: urlstr];

Mpmoviewplayerviewcontroller * playervc =
[[Mpmovieplayerviewcontroller alloc] initwithcontenturl: mediafileurl] autorelease];

[Self presentmodalviewcontroller: playervc animated: Yes];

[[Playervc movieplayer] Play];

When using a local media file for instantiation, The ios4.x series can be played normally, but when ios5.x is reached,

The following method must be used for instantiation. Otherwise, the media file cannot be played normally. (I personally tested, as I said. Otherwise, the player. view is not visible on the interface)

Nsurl * mediafileurl = [[nsurl alloc] initfileurlwithpath: filepath];

In addition, you can use nsicationicationcenter to obtain various events related to media file playback.
For example:

[[Nsicationcenter center defacenter center] removeobserver: Self
Name: mpmovieplayerplaybackdidfinishnotification
Object: Self. playervc. movieplayer];

[[Nsicationcenter center defacenter center] addobserver: Self
Selector: @ selector (mediafinishedcallback :)
Name: mpmovieplayerplaybackdidfinishnotification
Object: Self. playervc. movieplayer];

For more observer information, see Apple's documentation.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.